我正在使用MySQL在PHP中尝试一个非常简单的代码。 注意:我使用localhost和xampp。
这是我遇到的很多错误之一,有人可以帮我解决我对PHP很新的代码并且似乎无法找到错误。
这是我的代码:
<form method="post">
<input type="email" name="email" id="email" />
<input type="password" name="pass" id="pass" />
<input type="submit" name="submit" id="submit" value="Sign up!" />
<?php
$error = "";
$dbhost = 'localhost';
$username = 'root';
$password = '';
$db = 'users';
if($_POST['submit']) {
if(!$_POST['email']) $error.="Please enter an email";
else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email address";
if(!$_POST['pass']) $error.="<br />Please enter a password";
else{
if (strlen($_POST['pass']<8)) $error.="<br />Please enter at least 8 characters";
if (!preg_match('`[A-Z]`', $_POST['pass'])) $error.="<br />Please use at least one capital letter";
}
if($error) echo $error;
else {
$link = mysql_connect($dbhost,$username,$password, $db);
$query = "SELECT * FROM `users` WHERE email ='".mysqli_real_escape_string($link, $_POST['email'])."'";
$result = mysqli_query($link, $query);
$results = mysqli_num_rows($result);
if($results) echo "that email address is already registered";
else {
$query ="INSERT INTO `users` (`email, `password`) VALUES("'.mysqli_real_escape_string($link, $_POST['email']).'", md5(md5($_POST['email']).$_POST['password'])"')";
mysqli_query($link, $query);
echo "You've been signed up!";
}
}
?>