Hi All,
I've been working on a piece of code to check for duplicate username records in a MySQL database. If there is already a username in the database that the user is trying to register with, it displays an error. If not, it writes a row with the person's information to the database. The problem is that, with the way I currently have it written, it is skipping the validation and trying to write to the database anyway. Here is what I have:
$sql_query = "SELECT COUNT(*) from users WHERE username = '$uname'";
$result = mysql_query($sql_query);
if(mysql_num_rows($result) == 0) {
echo "<script>alert('Sorry, that username already exists. Please choose another.');history.back(-1);</script>";
}
else{
$sql="INSERT INTO `users` (`fname`, `lname`, `email`, `username`, `password`, `insert_time`) VALUES ('$fname', '$lname', '$email', '$uname','$password' ,'$date')";
}
I'm hoping maybe one of you can see something that I don't.
Thanks!