Jump to content

Checking db for usernames that already exist


wright67uk

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>';



}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.