I have a register script, which (Before adding a new account to the database) looks to make sure that the user's email address has not already been previously entered. Here it is:
PHP Code:
//checks for an account with the same email address
$sql = mysql_query("SELECT email FROM iusers WHERE email='$encryptemail'") or die(mysql_error());
$num_records = mysql_num_rows($sql);
if ($num_records > 0) {
header ("Location: ../content/register.php?overallerr=1&firstname=" . $firstname . "&lastname=" . $lastname . "&email=" . $email);
}
//inserts data into database
$query1 = "INSERT INTO iusers........ etc
Currently, it doesn't work. I can't find anything wrong with it. I can sign up with the same email address multiple times. (E.G. Even though $num_records should be greater than 0, it doesn't seem to be going into that IF statement.)
That header line should take the user back to the register page, and asks the user to input a different address. I tried to find out exactly what was happening, so I "echoed" the $num_records variable after the IF statement. Here's what it looks like now:
PHP Code:
//checks for an account with the same email address
$sql = mysql_query("SELECT email FROM iusers WHERE email='$encryptemail'") or die(mysql_error());
$num_records = mysql_num_rows($sql);
if ($num_records > 0) {
header ("Location: ../content/register.php?overallerr=1&firstname=" . $firstname . "&lastname=" . $lastname . "&email=" . $email);
}
echo ($num_records);
//inserts data into database
$query1 = "INSERT INTO iusers........ etc
When that echo statement is in there, the script works fine... The IF statement works, and I'm sent back to the register page. WHY? I didn't change anything important. When I delete the echo statement, the script stops working.
I'd keep it in there, but I have a header statement at the end of the script....
Thanks for any help you can provide,
Andrew
|