0

我在下面的代码中收到 2 个错误:

警告:mysqli::prepare() [mysqli.prepare]: (21S01/1136): 列数与第 115 行中第 1 行的值计数不匹配

致命错误:在第 119 行对 ... 中的非对象调用成员函数 bind_param()

我正在使用 mysqli 和 php 代码。我需要做什么才能修复这些错误?

代码:

$insertsql = "
INSERT INTO Teacher
(TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername, TeacherPassword, Code)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}                                           

$insert->bind_param("sssssss", $getfirstname, $getsurname,
         $getemail, $getid, $getuser,
         $teacherpassword, $code);

$insert->execute();

if ($insert->errno) {
// Handle query error here
}

$insert->close();
4

1 回答 1

0

您的 SQL 中有太多参数:

INSERT INTO Teacher 
    (TeacherForename, TeacherSurname, TeacherEmail, TeacherAlias, TeacherUsername,   
    TeacherPassword, Code)
VALUES
    (?, ?, ?, ?, ?, ?, ?, ?)

有 7 列和 8 个参数。

于 2012-08-24T20:43:50.620 回答