【问题标题】:an error and warning appearing in my php/mysqli [duplicate]我的 php/mysqli 中出现错误和警告 [重复]
【发布时间】:2012-08-20 10:10:51
【问题描述】:

我在下面的代码中收到 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();

【问题讨论】:

  • 你有7个参数,VALUES中有8个?;删除? 之一,看看这是否会使两条消息都消失......
  • @andrewsi 我以为我删除了 ?但我可以清楚地看到我没有。抱歉,感谢您的评论:)
  • @jprofitt - 这就是 mysqli 处理绑定参数的方式 - php.net/manual/en/mysqli-stmt.bind-param.php
  • @andrewsi 你是绝对正确的。在 PDO 领域工作太久了!

标签: php mysqli


【解决方案1】:

您的 SQL 中有太多参数:

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

共有 7 列和 8 个参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-28
    • 2019-07-29
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多