以下代码用于注册表单,并由WYSIWYG Web构建器自动生成。它一直说password
和confirmpassword
不一样。我不知道PHP的任何内容,所以我找不到错误。
我需要帮助:
<?php $mysql_server = 'db4free.net';
$mysql_username = '----';
$mysql_password = '----';
$mysql_database = '----';
$mysql_table = 'userdb';
$success_page = './userpage.php';
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform')
{
$newusername = $_POST['username1'];
$newemail = $_POST['email'];
$newpassword = $_POST['password1'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
$code = 'NA';
if ($newpassword!= $confirmpassword)
{
$error_message = 'Password and Confirm Password are not the same!';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername))
{
$error_message = 'Username is not valid, please check and try again!';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newpassword))
{
$error_message = 'Password is not valid, please check and try again!';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$.' &]{1,50}$/", $newfullname))
{
$error_message = 'Fullname is not valid, please check and try again!';
}
else
if (!preg_match("/^.+@.+\..+$/", $newemail))
{
$error_message = 'Email is not a valid email address. Please check and try again.';
}
if (empty($error_message))
{
$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!<br>'.mysql_error());
}
mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
$sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
$result = mysql_query($sql, $db);
if ($data = mysql_fetch_array($result))
{
$error_message = 'Username already used. Please select another username.';
}
}
if (empty($error_message))
{
$crypt_pass = md5($newpassword);
$newusername = mysql_real_escape_string($newusername);
$newemail = mysql_real_escape_string($newemail);
$newfullname = mysql_real_escape_string($newfullname);
$sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`, `code`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1, '$code')";
$result = mysql_query($sql, $db);
mysql_close($db);
$subject = 'Your new account';
$message = 'A new account has been setup.';
$message .= "\r\nUsername: ";
$message .= $newusername;
$message .= "\r\nPassword: ";
$message .= $newpassword;
$message .= "\r\n";
$header = "From: webmaster@yourwebsite.com"."\r\n";
$header .= "Reply-To: webmaster@yourwebsite.com"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($newemail, $subject, $message, $header);
header('Location: '.$success_page);
exit;
}
}
?>
答案 0 :(得分:0)
字段的名称&#39;密码1&#39;实际上是密码&#39;。只有ID是&#39;密码1&#39;,但在发布数据中没有使用。
答案 1 :(得分:0)
密码字段的名称是“password”。用户名字段相同。
您应该更改以下行:
$newusername = $_POST['username1'];
$newpassword = $_POST['password1'];
为:
$newusername = $_POST['username'];
$newpassword = $_POST['password'];