For some reason my script keeps saying "Please enter your passwords" and try again and never actually finishes. Any clues? Here is my code:(I put EXAMPLE where my website name is:
<?php
if (isset($_POST['submitted'])){
$trimmed = array_map('trim', $_POST);
$fn = $ln = $e = $p = FALSE;
//First Name
if (preg_match ('/^[A-Z \'.-]{2,20}$/i',$trimmed['first_name'])) {
$fn = mysql_real_escape_string($trimmed['first_name']);
$trimmed['first_name'];
} else {
echo "<p class='error'>Please Enter Your First Name</p>";
}
//Last Name
if (preg_match ('/^[A-Z \'.-]{2,40}$/i',$trimmed['last_name'])) {
$ln = mysql_real_escape_string($trimmed['last_name']);
$trimmed['last_name'];
} else {
echo "<p class='error'>Please Enter Your Last Name</p>";
}
//Check for an email address
if(preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) {
$e = mysql_real_escape_string($trimmed['email']);
} else{
echo "<p class='error'>Please Enter a Valid Email Address</p>";
}
//Password
if (preg_match ('/^\w{4,20}$/',$trimmed['password1'])){
if ($trimmed['password1'] == $trimmed['password2']) {
$p = mysql_real_escape_string($trimmed['password1']);
} else{
echo "<p class='error'>Your Password did not match the confirmed password</p>";
}
} else{
echo "<p class='error'>Please enter a valid Password</p>";
}
if($n && $ln && $e && $p) {
$q = "SELECT user_id from users WHERE email='$e'";
$r = mysql_query($link,$q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error($link));
if (mysql_num_rows($r) == 0){
$a = md5(uniqid(rand(), true));
$q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )";
$r= mysql_query ($link, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error($link));
if(mysql_affected_rows($link) == 1){
$body = "Thank you for signing up for a Example Account. To activate your account, please click on this link:\n\n";
开发者_Python百科 $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";
mail($trimmed['email'], 'Example Account Confirmation', $body, 'From: support@example.com');
echo"<h3>Thank You for Signing Up. A confirmation email has been sent to your email. Please click on the link we sent you to activate your account.</h3>";
exit();
} else{
echo "<p class='error'>You could not be registered due to a system error. We apologize for any inconvenience.</p>";
}
} else {
echo "<p class='error'>That email address has already been registered. If you have forgotten your password, please visit: <a href='./forgot.php'>Forgot Your Password?</a></p>";
}
} else{
echo"<p class='error'>Please re-enter your passwords and try again.</p>";
}
mysql_close($link);
}
?>
<form action='signup.php' method='post'>
<p><b>First Name:<br/></b><input type='text' name='first_name' size='20' maxlength='20' value='<?php if (isset($trimmed['first_name'])) { echo $trimmed['first_name'];} ?>'></p><br/>
<p><b>Last Name:<br/></b><input type='text' name='last_name' size='20' maxlength='40' value='<?php if (isset($trimmed['last_name'])) { echo $trimmed['last_name'];} ?>'></p><br/>
<p><b>Email<br/></b><input type='text' name='email' size='30' maxlength='80' value='<?php if (isset($trimmed['email'])) { echo $trimmed['email'];} ?>'></p><br/>
<p><b>Password<br/></b><input type='password' name='password1' size='20' maxlength='20' /><small> Use only letters, numbers, and underscores. Must be between 4-20 Characters Long.</small></p><br/>
<p><b>Confirm Password<br/></b><input type='password' name='password2' size='20' maxlength='20' /></p><br/>
<input type='hidden' name='submitted' value='true'/>
<input type='submit' name='submit' value='Sign Up!'/>
</form>
Easy. $fn = mysql_real_escape_string($trimmed['first_name']);
if($n && $ln && $e && $p)
You're checking $n
instead of $fn
, or setting $n
instead of $fn
, depending on how you look at it.
精彩评论