As usual, this is probably a matter of me just not seeing things very clearly, but I've got a piece of code I've been plugging at all day, and it simply DOES NOT want to play nice!
The background is: I'm creating a signup page that requires email verification before the user can choose a username, password or any details like that. I thought I was being easy on myself by creating two different signup tables:
Table 1: email_reg is where I store email addresses and a random md5 that is used for my verification link
Table2: users_login is where I store email addresses, usernames and passwords of folks who have clicked on the link I send them.
Where I'm having trouble is this:
I've got essentially 3 verifications of each email address that's entered.
Step 1 is to check and see if it is indeed an email address,
if step 1 passes, then we check it against the first database to see if its "registered, but not verified",
if step 2 turns up empty, then step 3 is to check if the email address is already assigned to a member of the site.
Once all three steps pass, a random md5 is generated, and an email (with a link) is sent.
If I remove all verification (for testing purposes this afternoon, everything works as it is supposed to ie: md5 generated, email sent, link works, etc.
Where I'm running into trouble is this: I've been doing these darn if-else statements all afternoon and gotten my head twisted, so I can't figure out where I'm going wrong.
When I load the page as shown in code below, I've get the following error
So, if someone would be so kind as to quickly look this over and point out what I think is probably a fairly silly mistake, I'd appreciate it:Code:Parse error: syntax error, unexpected T_ELSE in /var/www/public_html/testsite/register.php on line 30
Am I incorrect in thinking that I can nest if/else statements like this, drilling down until I encounter an error, or everything goes smoothly?Code:session_start(); require_once('script/fixedvars.php'); if (isset($_POST['submitted'])){ $errors = array(); require_once('script/dbcs.php'); require_once('script/is_email.php'); if (is_email(stripslashes(trim($_POST['email'])) )){ $email = mysql_real_escape_string($_POST['email']); $query = "SELECT email FROM $loginTable WHERE email = '$email'"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num == 0) { $email = mysql_real_escape_string($_POST['email']); $query = "SELECT email FROM $regTable WHERE email = '$email'"; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num == 0) { $regkey = md5(uniqid(rand(), true)); $regdate = date("Ymd"); $query = "INSERT INTO $regTable (email, regkey, regdate) VALUES ('$email', '$regkey', '$regdate')"; $result = @mysql_query($query); if (mysql_affected_rows() == 1) { $body = "Thank you for registering at TEST SITE. To activate your account, please click on this link:\n\n"; $body .= "http://localhost/testsite/activate.php?regkey=$regkey"; mail($_POST['email'], 'Registration Confirmation', $body, 'From: noreply@localhost'); header("location: registerconf.php?email=$email"); } else { $errors[] = 'sorry, we encountered a random error adding your email to our database, please try again in about 5 minutes'; //this is line 30, btw// } else { $errors[] = 'sorry, that email is already registered, but it hasn\'t been confirmed. Go check your email'; } else { $errors[] = 'sorry, that email is already registered have you forgotten your login details?'; } else { $errors[] = 'that doesn\'t appear to be a valid email address'; } } } } } } }
Obviously, in the html portion of the page, I have a php echo statement to handle the errors I'm throwing out.


Reply With Quote



Bookmarks