出于某种原因,我的脚本一直说“请输入您的密码”并再试一次,但实际上并没有完成。有线索吗?这是我的代码:(我把EXAMPLE放在我的网站名称:
<?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";
$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>
答案 0 :(得分:3)
易。 $fn = mysql_real_escape_string($trimmed['first_name']);
if($n && $ln && $e && $p)
您正在检查$n
而不是$fn
,或设置$n
而不是$fn
,具体取决于您如何看待它。