尝试在php中将用户插入我的用户表。插入查询似乎无法运行。我尝试手动添加电子邮件ID,它会检查重复的电子邮件ID,并且确实会出现错误,说明电子邮件ID存在,但由于某种原因,它不会插入到数据库中。有什么建议吗?`
<?php
$error = "";
if(array_key_exists("submit",$_POST )){
$link = mysqli_connect ("localhost", "root","","secretdi");
if (mysqli_connect_error()){
die ("Connection to Database failed!");
}
print_r($_POST);
if (!$_POST ['email']){
$error .= "Email Address is required<br>";
}
if (!$_POST ['password']){
$error .= "Password is required<br>";
}
if ($error != ""){
$error = "<p>There were Error(s) in your form <p>".$error;
}else {
$query = "SELECT id FROM `users` WHERE `email` = '".mysqli_real_escape_string($link,$_POST['email'])."' LIMIT 1 ";
$result = mysqli_query ($link, $query );
if (mysqli_num_rows($result) > 0){
$error = "That Email Address is already taken. Try to Log In ";
}else {
$query = "INSERT INTO `users` (`email`,`password`)VALUES ('".mysqli_real_escape_string($link, $_POST["email"])."','".mysqli_real_escape_string($link, $_POST["password"])."')";
}
if (!mysqli_query($link, $query )){
$error = "Could Not Sign You Up! Please Try Again Later. ";
} else{
echo "Sign-Up Successfull.";
}
}
}
?>
<div id = "error" > <?php echo $error; ?> </div>
<form method="post">
<input type = "email" name = "email" placeholder = " Your Email">
<input type = "password" name = "password" >
<input type = "checkbox" name = "checkbox">
<input type = "submit" name = "submit" value = "Sign - Up">
</form>`