wright67uk Posted February 17, 2013 Share Posted February 17, 2013 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/274607-checking-db-for-usernames-that-already-exist/ Share on other sites More sharing options...
requinix Posted February 17, 2013 Share Posted February 17, 2013 "SELECT * FROM registration WHERE uname = ".$uname." OR email = ".$email." LIMIT 1" You forgot the quotes. Link to comment https://forums.phpfreaks.com/topic/274607-checking-db-for-usernames-that-already-exist/#findComment-1413023 Share on other sites More sharing options...
P5system Posted February 18, 2013 Share Posted February 18, 2013 Query Should be like this "SELECT * FROM registration WHERE uname = '$uname' OR email = '$email' LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/274607-checking-db-for-usernames-that-already-exist/#findComment-1413067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.