Jump to content

Recommended Posts

I'm trying to make a signup page, but i'm coming into trouble when checking for usernames and email addresses that already exist.

 

note: My code is incomplete so I'm yet to check for things like correct email formats etc.

 

Im using a select statement and counting the results. If results are returned then I was expecting "this username or email address already exists!" to echo but it doesn't.

 

Would love a little help if anyone can help me!

 

 

<?php
if(isset($_POST['processForm']))


{
$uname = mysql_real_escape_string($_POST['uname']);
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$age = mysql_real_escape_string($_POST['age']);
$pass = mysql_real_escape_string($_POST['pass']);
$handicap = mysql_real_escape_string($_POST['handicap']);
$cpass = mysql_real_escape_string($_POST['cpass']);
$email = mysql_real_escape_string($_POST['email']);

if(empty($uname)) {echo "<br />You haven't entered a username<br/>"; $errors_found = true;}
if(empty($fname)) {echo "<br />You haven't entered your first name<br/>"; $errors_found = true;}
if(empty($lname)) {echo "<br />You haven't entered your last name<br/>"; $errors_found = true;}
if(empty($age)) {echo "<br />You haven't entered a your age<br/>"; $errors_found = true;}
if(empty($pass)) {echo "<br />You haven't entered a password<br/>"; $errors_found = true;}
if(empty($handicap)){echo "<br />You haven't entered a handicap<br/>"; $errors_found = true;}
if(empty($cpass)) {echo "<br />You haven't confirmed your password<br/>"; $errors_found = true;}
if(empty($email)) {echo "<br />You haven't entered an email address<br/>";$errors_found = true;}
if($pass != $cpass) {echo "<br/>Your passwords do not match!<br/>"; $errors_found = true;}


$Select = "SELECT * FROM registration WHERE uname = ".$uname." OR email = ".$email." LIMIT 1";
$Result = mysql_query($Select);

if (mysql_num_rows($Result) > 0) {echo 'this username or email address already exists!'; $errors_found = true;}

}

if (!$errors_found)

{$sql = "INSERT INTO registration (uname, fname, lname, age, handicap, pass, email, status)
VALUES ('$uname', '$fname', '$lname', '$age', '$handicap','$pass','$email','1')";


mysql_query($sql);

echo '<span class="thanks"><br/>Thankyou for registering, you can now <a href="login.php">log in</a></span>';



}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.