Ok, well I have an issue that i've tried many(and mean many) times to solve now and I have not been successful. So here is the problem:
When a user registers for my website if they enter the same name as a name already in the database but not a email then it makes another record with the same name(it can also have the same password) just without an email, but if you make an account with the same name,password(really doesn't matter),and email then it will save the account is already taken.
Code:
<?php
$username="*********";
$password="*********";
$database="*********";
$username=$_POST['user'];
$password=$_POST['pass'];
$email=$_POST['email'];
$con = mysql_connect("*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("****", $con);
$result = mysql_query("SELECT * FROM `userslogin` WHERE `username`= '" . $username . "' AND `email`= '" . $email . "'");
$num_rows = mysql_num_rows($result);
if ($num_rows != 0)
{
echo "Either the email or username is already in use.";
}
elseif ($num_rows != 1)
{
$sql="INSERT INTO userslogin (username, password, email)
VALUES
('$_POST[user]','$_POST[pass]','$_POST[email]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your information as been emailed to you. You may now log in and have fun =D!";
$to = "$email";
$subject = "SacredHost";
$message = "Thanks for registering at: *****.(\n)Username: $username(\n)Password: $password (";
$from = "****";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
}
mysql_close($con)
?>
Any help would be awesome! Am going to bed now, tired. Thanks in advance.