I setup this signup form for my website. People enter their username, email and password and then it uses php to add it to my database. But I keep getting this error when I run my code. My html file is on my AWS server as well as this PHP file, so I believe there must be an error in my code. I am still very new to PHP.
HTML:
<form method="get" action="signup_form.php">
<input style="width: 300px; display: block; margin-left: auto; margin-right: auto;" type="text" name="signup_name" placeholder="Screen Name">
<br>
<input style="width: 300px; display: block; margin-left: auto; margin-right: auto;" type="text" name="signup_mail" placeholder="Your E-mail">
<br>
<input style="width: 300px; display: block; margin-left: auto; margin-right: auto;" type="password" name="signup_password" id = "password" placeholder="Create Password" required>
<br>
<input style="width: 300px; display: block; margin-left: auto; margin-right: auto;" type="password" name="confirm_password" id = "confirm_password" placeholder="Repeat Password" required>
<br>
<br>
<button onclick="validatePassword()" class="button" style="display: block; margin-left: auto; margin-right: auto;" type="submit" name="submit_login">
SUBMIT
</button>
</form>
and here is my PHP code:
<?php
$signup_name = filter_input(INPUT_GET, 'signup_name');
$signup_mail = filter_input(INPUT_GET, 'signup_mail');
$signup_password = filter_input(INPUT_GET, 'signup_password');
if (!empty($signup_name)){
if (!empty($signup_mail)){
$host = "wildwea.......onaws.com";
$dbusername = "a....in";
$dbpassword = ".Bi....4.";
$dbname = "innodb";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());
}
else{
$sql = "SELECT EXISTS (SELECT 1 FROM Users WHERE Email = $signup_mail);"
if ($sql = 0){
$sql = "INSERT INTO Users (Username, Email, Pword)
values ('$signup_name', '$signup_mail',md5('$signup_password'))";
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
}
else{
echo "Error: ". $sql ."
". $conn->error;
}
$conn->close();
} else {
echo "User already in database";
}
}
}
else{
echo "Password should not be empty";
die();
}
}
else{
echo "Username should not be empty";
die();
}
?>
If you want to see the error here is the link to the sign up page:
http://thewildwear.com/signup.html
We can't see your specific error (looks like there might be multiple) so we won't be able to help you out there. But I could make a suggestion about how to structure your script.
Caveat - this really isn't a good approach for anything but the smallest of applications or for learning.
The main idea is that there is only 1 script and it has processing and display sections. It will only go into the processing section when the form is actually submitted.
If there are any validation errors, it will fall through to the display section and list out the errors and the form.
If there are no validation errors, it will save to the DB and redirect to some other page.
As you develop bigger (and better) applications, you might find that this type of coding will quickly become unwieldy - you're mixing validation, SQL, views/display, etc. all in a single script. They will become more complex and before long you'll have a big ball of spaghetti. Once you hit this point, start looking into frameworks.
But for now, keep on going. Good luck.
<?php
// A list of validation errors. Initialize to an empty list.
$errors = [];
/****************************/
/******** PROCESSING ********/
/****************************/
// The form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Values submitted from form
$name = $_POST['signup_name'];
$email = $_POST['signup_mail'];
$password = $_POST['signup_password'];
// Validation
if (empty($name)) {
$errors[] = 'Please enter your name';
}
if (empty($email)) {
$errors[] = 'Please enter your email';
}
// ... check if email already exists in your DB.
// ... more validation here
// There are no validation errors, process the form.
if (empty($errors)) {
// At this point, you now have a valid form. Just save it to the DB.
// Redirect to somewhere
}
}
/****************************/
/********** DISPLAY *********/
/****************************/
if (count($errors) > 0) : ?>
<ul>
<?php foreach ($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<!-- Use "post" and remove action and it will post to itself. -->
<form method="post">
<!-- ... -->
Related
Contact Form on my website stopped working after adding implementing SSL, it's PHP based and was working fine for 5 years before when it was just http.
Now when the form is filled correctly the message *"Sorry! Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field completed, and please also address any issues listed below:" keeps appearing.
It might be a simple issue but I don't know PHP and found this on a tutorial - would really help if anyone point out the issue and how to resolve it.
I can provide more details if needed.
Thanks!!
<?php
// Information to be modified
$your_email = "mail#website.com"; // email address to which the form data will be sent
$subject = "Visitor Message from Website"; // subject of the email that is sent
$thanks_page = "thankyou.htm"; // path to the thank you page following successful form submission
$contact_page = "../contact.htm"; // path to the HTML contact page where the form appears
// Nothing needs to be modified below this line
if (!isset($_POST['submit'])) {
header( "Location: $contact_page" );
}
if (isset($_POST["submit"])) {
$nam = $_POST["name"];
$ema = trim($_POST["email"]);
$com = $_POST["comments"];
$spa = $_POST["spam"];
if (get_magic_quotes_gpc()) {
$nam = stripslashes($nam);
$ema = stripslashes($ema);
$com = stripslashes($com);
}
$error_msg=array();
if (empty($nam) || !preg_match("~^[a-z\-'\s]{1,60}$~i", $nam)) {
$error_msg[] = "The name field must contain only letters, spaces, dashes ( - ) and single quotes ( ' )";
}
if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) {
$error_msg[] = "Your email must have a valid format, such as name#mailhost.com";
}
$limit = 1000;
if (empty($com) || !preg_match("/^[0-9A-Za-z\/-\s'\(\)!\?\.,]+$/", $com) || (strlen($com) > $limit)) {
$error_msg[] = "The Comments field must contain only letters, digits, spaces and basic punctuation ( ' - , . ), and has a limit of 1000 characters";
}
if (!empty($spa) && !($spa == "4" || $spa == "four")) {
echo "You failed the spam test!";
exit ();
}
// Assuming there's an error, refresh the page with error list and repeat the form
if ($error_msg) {
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
<style>
body {background: #f7f7f7; font: 100%/1.375 georgia, serif;padding: 20px 40px;}
form div {margin-bottom: 10px;}
.content {width: 40%; margin: 0 auto;}
h1 {margin: 0 0 20px 0; font-size: 175%; font-family: calibri, arial, sans-serif;}
label {margin-bottom: 2px;}
input[type="text"], input[type="email"], textarea {font-size: 0.75em; width: 98%; font-family: arial; border: 1px solid #ebebeb; padding: 4px; display: block;}
input[type="radio"] {margin: 0 5px 0 0;}
textarea {overflow: auto;}
.hide {display: none;}
.err {color: red; font-size: 0.875em; margin: 1em 0; padding: 0 2em;}
</style>
</head>
<body>
<div class="content">
<h1>Sorry!</h1>
<p>Unfortunately, your message could not be sent. The form as you filled it out is displayed below. Make sure each field completed, and please also address any issues listed below:</p>
<ul class="err">';
foreach ($error_msg as $err) {
echo '<li>'.$err.'</li>';
}
echo '</ul>
<form method="post" action="', $_SERVER['PHP_SELF'], '">
<div>
<label for="name">Name</label>
<input name="name" type="text" size="40" maxlength="60" id="name" value="'; if (isset($_POST["name"])) {echo $nam;}; echo '">
</div>
<div>
<label for="email">Email Address</label>
<input name="email" type="email" size="40" maxlength="60" id="email" value="'; if (isset($_POST["email"])) {echo $ema;}; echo '">
</div>
<div>
<label for="comm">Comments</label>
<textarea name="comments" rows="10" cols="50" id="comm">'; if (isset($_POST["comments"])) {echo $com;}; echo '</textarea>
</div>
<div class="hide">
<label for="spam">What is two plus two?</label>
<input name="spam" type="text" size="4" id="spam">
</div>
<div>
<input type="submit" name="submit" value="Send">
</div>
</form>
</body>
</html>';
exit();
}
$email_body =
"Name of sender: $nam\n\n" .
"Email of sender: $ema\n\n" .
"COMMENTS:\n\n" .
"$com" ;
// Assuming there's no error, send the email and redirect to Thank You page
if (isset($_REQUEST['comments']) && !$error_msg) {
mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>");
header ("Location: $thanks_page");
exit();
}
}
So I have a question textbox that appears after you select a checkbox, now the checkbox and the questions that appear both have statements to check if they're left empty, now when you select one of the checkboxes for gender, and leave the question blank, it all works correctly, and if you don't select a checkbox it gives the error that the checkbox isn't checked, but it will also give an error saying "Notice: Undefined index: gender in C:\xampp\htdocs\php\testfile.php on line 54"
I did try some research before posting this, and none of the solutions I could find really matched up to my problem.
<html>
<head>
<title>Income Program</title>
<style>
.male-question1 {
display: none;
margin: 10px 0 0 35px;
}
#male:checked ~ .male-question1 {
display: block;
}
.female-question1 {
display: none;
margin: 10px 0 0 35px;
}
#female:checked ~ .female-question1 {
display: block;
}
div {
background-color: white;
border: 1px solid black;
padding: 10px;
width: 650px;
}
</style>
</head>
<div>
<form name="frm1" action="#" method="post" onsubmit="return checkCheckBoxes(this);">
<label for="gender">Gender:</label><br>
<input type="radio" name="gender" id="male" value="Male"/>
<label for="male">Male</label>
<input type="radio" name="gender" id="female" value="Female" />
<label for="female">Female</label>
<div class="male-question1">
<label for="gendertext">Please enter your height and weight (ie. 6'2 and 175 lbs)</label> <br>
<textarea id="gendertext" name="gendertext"></textarea>
</div>
<div class="female-question1">
<label for="gendertext2">Please enter your marital status (ie. Single, Married, Divorced)</label> <br>
<textarea id="gendertext2" name="gendertext2"></textarea>
</div>
<input type="submit" name="submitbtn" value="Submit Form" />
</form>
</div>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$error_msg= array();
if(!isset($_POST['gender'])){
$error_msg[] = "ERROR: No Gender selected.";
}
$selected_radio=$_POST['gender']; //THE ERROR
if ($selected_radio=='Male') {
if($_POST['gendertext']==""){
$error_msg[] = "ERROR: Please Answer Gender Question";
}
}
if ($selected_radio=='Female') {
if($_POST['gendertext2']==""){
$error_msg[] = "ERROR: Please Answer Gender Question";
}
}
$gendertext=$_POST['gendertext'];
$gendertext2=$_POST['gendertext2'];
if (isset($error_msg) && count($error_msg) == 0) {
echo "Gender: ".$_POST['gender']."<br>"."<br>";
echo "Your textbox answer:" . " " . $gendertext . $gendertext2 ."<br>"."<br>";
echo "<br>";
echo "Submitted Successfully";
}
else{
foreach ($error_msg as $result) {
echo $result;
echo "<br>";
}
}
}
?>
The code above should run and replicate the problem, if you submit with a box checked, it works, if you submit with everything filled out, it works, if you submit with no box checked, it gives the error.
When you detect that $_POST['gender'] is not set, you need to skip over the rest of the code that tries to use it.
if(!isset($_POST['gender'])){
$error_msg[] = "ERROR: No Gender selected.";
} else {
$selected_radio=$_POST['gender']; //THE ERROR
if ($selected_radio=='Male') {
if($_POST['gendertext']==""){
$error_msg[] = "ERROR: Please Answer Gender Question";
}
}
if ($selected_radio=='Female') {
if($_POST['gendertext2']==""){
$error_msg[] = "ERROR: Please Answer Gender Question";
}
}
}
I'm relatively new to the web development scene and have been assigned with creating a website capable of logging calls.
I have used a HTML form to achieve this - I have made many of these in the past, but have never encountered this issue before.
My page contains 3 buttons: one to log a call, one to forward a call, and one to view all call logs. I achieve this by using an onclick method in the buttons:
<button type=submit value=log onclick="window.location.href='reception.php?log=1';">Log a call.</button>
And then using PHP GET to display the appropriate content on the rest of the page.
try {
$log = $_GET["log"];
}
catch(Exception $ex) {
die();
}
if($log) {
?>
// create form
This works perfectly, and I have created my form as below.
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" name="log">
<p>
<label>Call date: </label>
<input type="date" name="date" value=<?php echo date("Y-m-d"); ?>>
<span class="error"><sup> <?php echo $dateErr; ?></sup></span>
</p>
<br>
<p>
<label>Does the client have a contract?</label>
<select name="contract">
<option value="default" selected disabled>Please select...</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
<span class="error"><sup> <?php echo $contractErr; ?></sup></span>
</p>
<br>
<p>
<label>Client forename:</label>
<input type=text name="fname" <?php if(isset($fname)) echo "value='".$fname."'";?>>
<span class="error"><sup> <?php echo $fnameErr; ?></sup></span>
</p>
<br>
<p>
<label>Client surname:</label>
<input type=text name="sname">
<span class="error"><sup> <?php echo $snameErr; ?></sup></span>
</p>
<br>
<p>
<label style="position: relative; top: -135px;">Client enquiry:</label>
<textarea name=enq style="font-size: 14px; height: 150px; width: 300px;"></textarea>
<span class="error"><sup> <?php echo $enqErr; ?></sup></span>
</p>
<br>
<p>
<button type=submit name=submit value=submit style="position:relative; right: -115px; height:40px; width: 100px;">Submit</button>
</p>
It works just fine. However, the issue comes when submitting the form: for some reason, all PHP variables that I define come up empty when submit is clicked, meaning that any auto-completion / error messages do not show up. As you can see in my form code, as a test I made it autofill the "fname" field if the user has already set it, but it does not work.
Here is my PHP for validation (it is not complete yet, I just wanted to do all of the 'isset' checks first):
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if(isset($_POST["submit"])) {
$go = true;
$query = "INSERT INTO callLog VALUES(NULL, '";
if(empty($_POST["date"])) {
$dateErr = "* Please enter a date.";
$go = false;
}
else {
$query .= date('Y-m-d', strtotime($_POST["date"]))."', ";
}
if(empty($_POST["contract"])) {
$contractErr = "* Please select 'Yes' or 'No'.";
$go = false;
}
else {
$contract = test_input($_POST["contract"]);
if($contract == "Yes") {
$contract = "TRUE";
}
else {
$contract = "FALSE";
}
$query .= $contract.", '";
}
if(empty($_POST["fname"])) {
$fnameErr = "* Please enter a forename.";
$go = false;
}
else {
$fname = test_input($_POST["fname"]);
$query .= $fname."', '";
}
if(empty($_POST["sname"])) {
$snameErr = "* Please enter a surname.";
$go = false;
}
else {
$sname = test_input($_POST["sname"]);
$query .= $fname."', '";
}
if(empty($_POST["enq"])) {
$enqErr = "* Please enter an enquiry.";
$go = false;
}
else {
$query .= $enq."');";
}
if($go) {
$conn->query($query);
header('Location: reception.php');
}
?><script>
$(document).ready(function() {
window.location.href='reception.php?log=1';
});
</script><?php
}
}
The JS at the end is simply so that the page redirects to the call log form page once the data has been submitted, rather than having to click the 'call log' button again.
I'm completely at a loss as to why this doesn't work. Aside from the 'GET' method to display the page, I've done everything as I have in the past which has worked fine. Is it the 'GET' method interfering, or am I missing something?
I have seen that potentially trying something such as Ajax to handle the submission to see if it will work is a possibility, but I am not too familiar with JQuery (knowing only the basics) and do not know how to work with Ajax.
Thanks!
You're highjacking the form submission. You're onclick="window.location.href='reception.php?log=1';" just makes a GET request to that page, not a POST to your form action.
I'm creating a new booking system for my employer, in which a form is filled in and data enters a pre-built MySQL database.
I'm honestly unsure as to what I am doing wrong. Originally the data would not post into the database, but the form would appear to have submitted. Now, the form just submits to a white page. I will submit the full page code below as there's no comprimising data there, and hopefully somebody will be able to help.
<head>
<title> Moat Laptop Bookinge </title>
<?php
if (isset($_POST['submitted'])) {
include('booking_db.php');
$name = $_POST['name'];
$out = $_POST['out'];
$in = $_POST['in'];
$sqlinsert = "INSERT INTO Future (name, out, 'in') VALUES ('$name', '$out', '$in')";
if (!mysqli_query ($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "Laptop has been successfully Booked!";
}
?>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>
<script>
$(document).ready(function() {
$("#datepicker2").datepicker();
});
</script>
</head>
<body style="background-height: 100%;background-width: 100%;background: #141E30;background: -webkit-linear-gradient(to left, #141E30 , #243B55);background: linear-gradient(to left, #141E30 , #243B55);">
<div id="logo" style="font-family: Tw Cen MT; font-weight: Bold; position: fixed; color: white; left: 650px;top: 35px; font-size: 80px;text-shadow: 3px 3px #c7c7c7;">
Book a Laptop
</div>
<div id="content_box" style="background-color: white;position: fixed; left: 450px;top: 135px; width:60%; height: 70%; border-radius: 3px;">
<center>
<form method="post" action="book.php" style="font-family: Bodoni MT;">
<input type="hidden" name="submitted" value="true" />
<br />
<br />
<b><legend>First Name and First Letter of Surname</legend></b>
<input type="text" name="name" value="Ex. James T" />
<br/>
<br />
<b><legend>When will you need to collect the device?</legend></b>
<input id="datepicker2" name="out" />
<br/>
<br />
<b><legend>When will you return the device?</legend></b>
<input id="datepicker" name="in" />
<br />
<input type="submit" value="Confirm Booking" />
</center>
<?php
echo $newrecord
?>
</div>
</body>
If you need any more information, within reason, feel free to ask.
EDIT
This issue has been resolved, I cannot mark the answer as it was my answer and I have to wait 2 days. THank you for all of the answers.
There could be a problem in the line include('booking_db.php');. You should mention error_reporting(E_ALL); at the top of the page, and try debugging:
error_reporting(E_ALL);
if (isset($_POST['submitted'])) {
var_dump(file_exists('booking_db.php')); //check if you get true or false
require 'booking_db.php'; // Change include to required
echo "Test";
exit;
$name = $_POST['name'];
echo $name; // Check
$out = $_POST['out'];
$in = $_POST['in'];
$sqlinsert = "INSERT INTO Future (name, out, 'in') VALUES ('$name', '$out', '$in')";
var_dump($dbcon); // check
if (!mysqli_query ($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "Laptop has been successfully Booked!";
}
Please check what you're getting after form submit.
Replace your insert query with :
INSERT INTO Future
(`name`,`out`,`in`) VALUES ('".$name."', '".$out."', '".$in."')
and
if (isset($_POST['submitted'])) with if (isset($_POST['Confirm Booking']))
because you have to put your value of submit button in POST
Turns out, my issue was with
if (!mysqli_query ($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "Laptop has been successfully Booked!";
}
I changed this to
if (mysqli_query ($link, $sqlinsert)) {
echo "";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
And changed a few variables to match up with this, and it started working and posted to my DB. Thank you to anyone who answered.
<?php
include ('database_connection.php');
include ('navigs.php');
if (isset($_POST['formsubmitted'])) {
$error = array();//Declare An Array to store any error message
if (empty($_POST['firstname'])) {//if no name has been supplied
$error[] = 'Please enter your firstname ';//add to array "error"
} else {
$firstname = $_POST['firstname'];//else assign it a variable
}
if (empty($_POST['nickname'])) {
$error[] = 'Please enter your nickname';
} else {
$nickname = $_POST['nickname'];
}
if (empty($_POST['email'])) {
$error[] = 'Please enter your e-mail ';
} else {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email'])) {
//regular expression for email validation
$email = $_POST['email'];
} else {
$error[] = 'Your email address is invalid ';
}
}
if (empty($_POST['altemail'])) {
$error[] = 'Please enter your alternative email';
} else {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['altemail'])) {
$altemail = $_POST['altemail'];
} else {
$error[] = 'Not a valid email ';
}
}
if (empty($_POST['password'])) {
$error[] = 'Please enter a password ';
} else {
$password = $_POST['password'];
}
if (empty($error)) //send to Database if there's no error '
{ // If everything's OK...
// Make sure the email address is available:
$query_verify_email = "SELECT * FROM users WHERE Email ='$email' OR Altemail='$altemail' OR nickname='$nickname'";
$result_verify_email = mysqli_query($dbc, $query_verify_email);
if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
echo ' Database Error ';
}
if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .
// Create a unique activation code:
$activation = md5(uniqid(rand(), true));
$query_insert_user = "INSERT INTO `users` ( `firstname`, `nickname`, `email`, `activation`, `altemail`, `password` ) VALUES ( '$firstname', '$nickname', '$email', '$activation', '$altemail', ENCRYPT('$password'))";
$result_insert_user = mysqli_query($dbc, $query_insert_user);
if (!$result_insert_user) {
echo 'Erreur SQL ';
}
if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.
// Send the email:
$message = " Pour activer ton compte, click sur ce lien:\n\n";
$message .= WEBSITE_URL . 'activate.php?email=' . urlencode($email) . "&key=$activation";
mail($altemail, 'Registration Confirmation', $message, 'From: noreply#mysite.org');
// Flush the buffered output.
// Finish the page:
echo '<div class="success">An email has been sent to the following addres: '.$altemail.' Please click on the link to activate your account </div>';
} else { // If it did not run OK.
echo '<div class="errormsgbox">An error has occurred please try again later .</div>';
}
} else { // The email address is not available.
echo '<div class="errormsgbox" >Either the nickname is already taken, the email address is already taken, or the alternative email you supplied is already on our system</div>';
}
} else {//If the "error" array contains error msg , display them
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values) {
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';
}
mysqli_close($dbc);//Close the DB Connection
} // End of the main Submit conditional.
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Create you email account</title>
<style type="text/css">
body {
font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.registration_form {
margin:0 auto;
width:500px;
padding:14px;
}
label {
width: 10em;
float: left;
margin-right: 0.5em;
display: block
}
.submit {
float:right;
}
fieldset {
background:#EBF4FB none repeat scroll 0 0;
border:2px solid #B7DDF2;
width: 500px;
}
legend {
color: #fff;
background: #80D3E2;
border: 1px solid #781351;
padding: 2px 6px
}
.elements {
padding:10px;
}
p {
border-bottom:2px solid #B7DDF2;
color:#666666;
font-size:13px;
margin-bottom:20px;
padding-bottom:9px;
}
a{
color:#0099FF;
font-weight:bold;
}
/* Box Style */
.success, .warning, .errormsgbox, .validation {
border: 1px solid;
margin: 0 auto;
padding:10px 5px 10px 50px;
background-repeat: no-repeat;
background-position: 10px center;
font-weight:bold;
width:450px;
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('images/success.png');
}
.warning {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('images/warning.png');
}
.errormsgbox {
color: #D8000C;
background-color: #FFBABA;
background-image: url('images/error.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('images/error.png');
}
</style>
</head>
<body>
<form action="index.php" method="post" class="registration_form">
<fieldset>
<legend>Créer Un Compte Mail </legend>
<p>Create an email account <span style="background:#EAEAEA none repeat scroll 0 0;line-height:2;margin-left:220px;;padding:7px 7px;">Tu as un compe? Login</span> </p>
<div class="elements">
<label for="firstname">Firstname / Initiale :</label>
<input type="text" id="firstname" name="firstname" size="25" />
</div>
<div class="elements">
<label for="nickname">NickName :</label>
<input type="text" id="nickname" name="nickname" size="25" />
</div>
<div class="elements">
<label for="email">E-mail :</label>
<input type="text" id="email" name="email" size="25" />
</div>
<div class="elements">
<label for="altemail">Email de verification :</label>
<input type="text" id="altemail" name="altemail" size="25" />
</div>
<div class="elements">
<label for="password">Your Password :</label>
<input type="password" id="password" name="password" size="25" />
</div>
<div class="submit">
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" value="Submit" />
</div>
</fieldset>
</form>
Go Back to Account Verification on sign up
</body>
Hi all What I am trying to achieve here is this:
When a user enters a username, an email address and an alternative email, to be able to check whether these entries do not already exist in the database and return an error accordingly.
For instance if the username is already taken it will warn the user to choose another usename and so on.
At the moment it only returns one error if any of the three entries is found, how can I do it in order to return an error according to the entry that is found in the table Please.
As an update, my question initially was to check two separate fields within the table,
First this form is to allow people to create their own email account, but for doing so, they also need to provide an existing email address in order to send them a link to activate their account.
I can check the three fields successfully but the problem I am having, is how to return an error for each of the fields separately.
At the moment I am only able to return the same error for any of the fields.
First it will check the validity of the email addresses
Second it will check if the email addresses both are not already on the system, the one the user is trying to create and the one he's providing as an alternative email address
Third it will check if the nickname is already taken.
Right now it does all of the above, the only problem I am having is how to get it to return an error for each one.
So the user won't get confused, and s/he would know which field to change in order to complete his / her registration.
If you could help me with just this
} else { // The email address is not available.
echo '<div class="errormsgbox" >Either the nickname is already taken, the email address is already taken, or the alternative email you supplied is already on our system</div>';
}
Thank you all for your help it is much appreciated
Do some print_r($error) between the different calls. Or use xdebug in order to step through your code.
Anyway I would advise you about using a CMS or Framework to build upon and not mixing all up in one file.
I suggest using a framework like Kohana, will make your life easier. This will also give you the ability to make sure only the specified fields are going through to the database, and sanitized. Don't want to deal with mass assignment (I'm bender from the future)
Create a set of rules for the available fields
$rules = array(
'email' => array(
'valid_email',
'not_empty'
),
'nickname' => array(
'not_empty',
)
)
Write a method to check against the rules and the get the messages back or return it to true.
foreach ($_POST as $field)
{
if (isset($rules[$field]))
{
// Check the rules
foreach ($rules[$field] as $rule)
{
$check = call_user_func(array(Valid, $rule), $field);
if ( !$check->isValid )
{
$this->errors[] = $check->message;
}
else
{
// Insert or do whatever you need to with the data
}
}
}
}