[英]PHP prepared statement cannot work.And I don't know what is going wrong
Code below here cannot work.And I don't know where the problem is: 下面的代码无法正常工作,我也不知道问题出在哪里:
$insert_str="insert into User(Name,Password)values(?,?)";
$stmt->$conn->prepare($insert_str);
$stmt->bind_param("ss",$name,$password);
$stmt->execute();
$stmt->close();
I can gurantee that mysql connection and mysql configuration are ok.Because code like this works: 我可以保证mysql连接和mysql配置都可以,因为这样的代码有效:
$insert_str="insert into User(Name,Password)values('$name','$password')";
$conn->query($insert_str);
echo "Create Account Successfully";
Could someone help please? 有人可以帮忙吗? I have being considering potential problems for over 2 hours but nothing changed.
我已经考虑了2个多小时的潜在问题,但没有任何改变。
You need to assign the variable $stmt as the return from the prepare statement, like this: 您需要将变量$ stmt分配为prepare语句的返回值,如下所示:
$insert_str="insert into User(Name,Password)values(?,?)";
$stmt=$conn->prepare($insert_str);
$stmt->bind_param("ss",$name,$password);
$stmt->execute();
$stmt->close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.