問題描述
我嘗試在php中將參數綁定到sql(mysqli),但是出現上面寫的錯誤代碼.這是我寫的代碼:
I try to bind parameters to sql (mysqli) in php, but there is an error code as written above. This is the code I wrote:
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade)
VALUES (?, ?, ?, ?)");
if ($stmt = false)
{
echo "false";
}
else{
$stmt->bind_param("sss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment, $protectiveGrade);
$stmt->execute();
}
這里是錯誤信息:11
致命錯誤:在布爾值上調用成員函數 bind_param()
Fatal error: Call to a member function bind_param() on boolean in
怎么了?
推薦答案
<?php
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade)
VALUES (?, ?, ?, ?)");
if (!$stmt) {
echo "false";
}
else {
$stmt->bind_param("ssss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment, $protectiveGrade);
$stmt->execute();
}
if ($stmt = false)
表示您將 false
分配給 $stmt
.將其替換為 if (!$stmt)
.
if ($stmt = false)
means you're assigning false
to $stmt
. Replace it with if (!$stmt)
.
您綁定了 4 個參數,但只提供了 3 種類型的值.我在 bind_param
函數中添加了一個 s
,假設您的所有值都是字符串.如果某些值是整數,則用 i
替換相應的 s
.如果有雙打,替換為 d
.
You're binding 4 parameters but only providing 3 types of values. I added a s
in the bind_param
function, assuming all your values are string. If some of the values are integers replace the corresponding s
with an i
. If there are doubles, replace with a d
.
您確定 assignments
表中第一個字段的名稱是 Classes_has_Subjects_classesHasSubjectsId
?
Are you sure the first field's name in the assignments
table is Classes_has_Subjects_classesHasSubjectsId
?
這篇關于在布爾值上調用成員函數 bind_param()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!