douxuanou2787 2014-01-07 18:23
浏览 130
已采纳

Prepared Statement无法通过引用传递参数2。

Getting the following error:

Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\ppa\php\process_images.php on line 29

Simply trying to update a database record, the following debug code

$id = (int)$x;
echo $id.". Type: ".gettype($id);

produces this: 4. Type: integer So the variable is the correct type.

Here is my code

if (isset($_POST['delete'])) {
    //Delete the image, first update the database, then move the image to a new folder. 
    foreach($_POST['product'] as $x) {
        if ($stmt = $mysqli->prepare("UPDATE images SET dodelete = ? WHERE id = ?")) {
            $id = (int)$x;
            echo $id.". Type: ".gettype($id);
            $stmt->bind_param("ii", 1, $id);   <---- line 29
            $stmt->execute();
            $stmt->close();
        } else {
            echo "Unable to delete image!";
        }
    }
}

At first I was binding the $x variable directly from the foreach statement, which I thought was the issue as the error says it can't pass parameter by reference, but as you can see I made a new variable $id.

  • 写回答

1条回答 默认 最新

  • doubi4340 2014-01-07 18:27
    关注
    $stmt->bind_param("ii", 1, $id);
                         ---^
    

    It's because 1 is not a parameter, it's an integer. You'll need to use bindValue instead.

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

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致