我是网络开发的新手,这是我在MySQL中的第一个代码(练习)。我的问题是代码(尽管是练习中提供的示例答案的副本)正在产生许多问题。最近是:
'它正在使用UPDATE命令复制条目'。我在网站和网站上尝试了很多解决方案但没有成功。
3.我希望你理解并帮助我。先谢谢一个星系。
<?php
$link= mysqli_connect(""); //connection details omitted
if (array_key_exists("submit",$_POST)): // checks when submitted
$error=""; //variable for errors
if (!$_POST['email']){
$error .= "An email address is required<br>"; //if email not entered
}
if (!$_POST['password']){
$error .= "A password is required<br>"; //if password missing
}
//if ($error != "")
//{
//$error = "<p>There were errors in your submission:</p>" . $error; //pre-text for errors joined with concatation
//}
else //if I use { or : it doesn't work,
//variable for query select and run result
$check ="select id from users where email='".mysqli_real_escape_string($link, $_POST['email'])."'";
// print_r($check);
$result =mysqli_query($link, $check);
if (mysqli_num_rows($result)>0) //check if an id is found with the given email
{
$error="This email address has been taken."; //echoed error
}else{
$email= mysqli_real_escape_string($link, $_POST['email']);
$password=mysqli_real_escape_string($link, $_POST['password']);
$insert = "insert into users (email, password) values ('$email', '$password') ";
//print_r($insert);//insert query
$result=mysqli_query ($link,$insert);
if (!mysqli_query($link, $insert)){
$error= "There was a problem. Try again!"; //the connection failed message
}
else
{
$id=mysqli_insert_id($link);
$md=md5(md5($id.$_POST['password']));
$hash="update users set password='$md' where id=$id";
mysqli_query($link, $hash);
echo "Sign Up successful!"; //success message
}
}
endif;
答案 0 :(得分:0)
您正在拨打mysqli_query
两次,以便INSERT
查询执行两次。
修复如下:
$result=mysqli_query ($link,$insert);
if (!$result){