View Full Version : Registration code

11-13-2012, 10:51 PM
The code for posting registration info to the database dies and does not display an error.

$message ='';


$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

//error handling
$message='Please insert all fields into the form below.';
if($pass1 != $pass2){
$message ='Your password fields do not match.';
//securing the values of the variables
$username = preg_replace("#[^0-9a-z]#i","",$username);
$fname = preg_replace("#[^0-9a-z]#i","",$fname);
$lname = preg_replace("#[^0-9a-z]#i","",$lname);
$pass1 = sha($pass1);
$email = mysql_real_escape_string($email);

//check duplicates
$user_query = mysql_query("SELECT username FROM members WHERE username='$username' LIMIT 1")or die("Could not check username");
$count_username = mysql_num_rows($user_query);

$user_query = mysql_query("SELECT email FROM members WHERE email='$email' LIMIT 1")or die("Could not check Email");
$count_email = mysql_num_rows($email_query);

if($count_username > 0){
$message ='Your username already exists.';
}else if($count_email > 0){
$message ='Your email already exists.';
// insert users
$query = mysql_query("INSERT INTO members (username, fname, lname, email, password, lastlogin, accounttype, emailactivated, joindate) VALUES('$username', '$fname', '$lname', '$email', '$password', '', '', '', now())")or die("Could not insert data.");
$member_id = mysql_insert_id();
$message ='You have now been registered.';

body section

Register to my site by filling in the fields below.
<p><?php print("$message");?></p>
<form action="register2.php" method="post">
<input type="text" name="username" placeholder="Username"/><br />
<input type="text" name="fname" placeholder="First Name"/><br />
<input type="text" name="lname" placeholder="Last Name"/><br />
<input type="text" name="email" placeholder="Email Address"/><br />
<input type="password" name="pass1" placeholder="Password"/><br />
<input type="password" name="pass2" placeholder="Validate your password"/><br />
<input type="submit" value="Register" />


11-14-2012, 12:03 AM
You don't have an entry called user in your form. You'll never pass the first isset check without it. Isset should be given every item you expect to be provided with to verify they exist prior to useing them.

11-14-2012, 01:03 AM
Thanks! I changed
if(isset($_POST['username'])) but it still died without firing off the form. I'm still a bit confused.

11-14-2012, 01:29 PM
Now you add a print. Currently the script generates no output so you cannot tell where you ended up. Add print $message; to the bottom of the script.

11-14-2012, 01:41 PM
I actually have a print at the top of the form. When I load the page on the server though, it never loads the form or the print.

11-14-2012, 04:49 PM
I'm not talking about a print on the form, I'm talking about a print on the processing script register2.php. No matter the outcome of the script, it produces no output.