dongping4273 2014-10-15 04:42
浏览 54
已采纳

将bind_param与MySQLi一起使用时出错[关闭]

Why am I getting an error with this code?

$stmt = $mysqli->prepare(
    "INSERT INTO buku VALUES (
        NULL,
        (SELECT id_penerbit FROM penerbit WHERE nm_penerbit = ?),
        (SELECT id_pengarang FROM pengarang WHERE nm_pengarang = ?),
        (SELECT id_kategori FROM kategori WHERE nm_kategori = ?),
        (SELECT id_lemari FROM lemari WHERE nm_lemari = ?),
        ?, ?, ?, ?, ?, 0, ?");
$stmt->bind_param("ssssssisss", $penerbit, $pengarang, $kategori, $lemari, $judul, $isbn, $hal, $terbit, $bahasa, $sinopsis);
if($stmt->execute()) showAlert("Berhasil mengubah kategori", "success");
else showAlert($stmt->error);

The error I'm getting is:

Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\eperpus\admin\buku-tambah.php on line 34

  • 写回答

1条回答 默认 最新

  • dongzhi4073 2014-10-15 05:01
    关注

    You're calling ->bind_param() on a non-object - which means there was an error in creating the object ($stmt) and it returned false - as documented.

    The only way to troubleshoot the problem would be to investigate why the ->prepare() call failed - an issue which is a tad bit hard to troubleshoot as an outsider with only access to one line of code:

    $stmt = $mysqli->prepare("INSERT INTO buku VALUES (NULL, (SELECT id_penerbit FROM penerbit WHERE nm_penerbit = ?), (SELECT id_pengarang FROM pengarang WHERE nm_pengarang = ?), (SELECT id_kategori FROM kategori WHERE nm_kategori = ?), (SELECT id_lemari FROM lemari WHERE nm_lemari = ?), ?, ?, ?, ?, ?, 0, ?");
    

    Edit: The query itself is bad, as it doesn't close the VALUES ( parenthesis. This was the issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化