I need to check for duplicate usernames and check if they already exist in the database or not. If they do, I show them an error message.
I am doing it with username but I also need to do it with the email address.
Here's my code so far:
if(isset($_POST['submit'])){
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$IP = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT username FROM Users WHERE username='".$username."'");
...
else if (mysql_num_rows($query) != 0)
{
echo "<p><b><center> <font color=\"red\">Username already exists.<br> </b>If you already have an account, please<a href = '../user/login.php'> click here </a> to login.</font></center></p>";
}
My question is how can I do the same for email? Do I need to have one another query for email so like $query = mysql_query("SELECT email FROM Users WHERE email='".$email."'");
and add it after the first query in the above code?
I tried doing it but it gives me an error. Thanks.