I have this code, and it does work for putting users into the database. The problem is, it is inserting them every time, even if I enter a username or an email that already exists, and I'm not sure why. I'm working with MySQL.
This is what I have so far:
$email = $_POST["email"];
$username = $_POST["username"];
$emailquery = mysql_query("SELECT * FROM users WHERE email='$email'");
$usernamequery = mysql_query("SELECT * FROM users WHERE username='$username'");
if(mysql_num_rows($emailquery) != 0)
{
echo "Email address already exists";
// redirect
$url = 'register.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
else if(mysql_num_rows($usernamequery) != 0)
{
echo "User name already exists";
// redirect
$url = 'register.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
else
{
$sql="INSERT INTO Users (FirstName, LastName, Email, UserName, Password)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]', '$_POST[username]', '$_POST[password]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$url = 'home.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
mysql_close($con);
}
Oops, I meant to post this in the PHP forum. Could a mod please move this?

New Topic/Question
Reply



MultiQuote





|