【发布时间】:2016-04-24 17:00:52
【问题描述】:
stackoverflow 上的很多人都遇到过这个问题,但我仍然无法发现错误
这是错误:
Fatal error: Call to a member function bind_param() on boolean -
这是代码行:
$insertpost = $conn->prepare("INSERT INTO posts (title,post,user,img,date,short) VALUES(?,?,?,?,NOW(),?)");
$insertpost->bind_param("sssss",$title,$comment,$user,$url,$short);
【问题讨论】:
-
$insertpost可能是 boolfalse,可能是因为prepare()失败。 -
您将所有字符串定义为参数类型,
"sssss",查看您的参数,您似乎拥有与您定义的类型不同的类型。我至少可以看到:日期/日期时间和整数类型。这只是一个建议,它们可能是隐式转换,但为了安全起见,我通常更喜欢正确输入内容,无论它们是否有隐式转换。 -
基本上查询 FAILED 因此变量
$insertpost包含 false 如果您测试这种情况 ALWAYS 你不会得到这个问题。 Aso 使用$conn->error来查看错误描述如果$insertpost === false -
$insertpost = "插入帖子(标题、帖子、用户、img、日期、短)VALUES('".$title."','".$comment."','" .$user."','".$url."','".$date."','".$short."')";我知道它有效,因为它以前有效...