Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用准备好的语句更新mysqli在bind_para失败_Php_Mysqli_Prepared Statement - Fatal编程技术网

Php 使用准备好的语句更新mysqli在bind_para失败

Php 使用准备好的语句更新mysqli在bind_para失败,php,mysqli,prepared-statement,Php,Mysqli,Prepared Statement,我正在将现有php程序中的SQL语句转换为mysqli准备的语句 我有一个语句失败了,出现了一个致命错误:在布尔错误上调用成员函数bind_param,但看不出原因 我已经试着看了这里所有相关的问题,但是没有一个答案是适用的 数据库格式为: 1管理员id Int11 2用户名varchar30 3密码varchar255 4级Int11 下面的PHP代码是它失败的代码区域。 插入代码工作正常,可以看出,更新代码最初是以相同的格式编写的。这一点已经被注释掉,目前使用跟踪回波来确定任何可能存在问题的

我正在将现有php程序中的SQL语句转换为mysqli准备的语句

我有一个语句失败了,出现了一个致命错误:在布尔错误上调用成员函数bind_param,但看不出原因

我已经试着看了这里所有相关的问题,但是没有一个答案是适用的

数据库格式为: 1管理员id Int11 2用户名varchar30 3密码varchar255 4级Int11

下面的PHP代码是它失败的代码区域。 插入代码工作正常,可以看出,更新代码最初是以相同的格式编写的。这一点已经被注释掉,目前使用跟踪回波来确定任何可能存在问题的地方。 在到达特定代码之前,所有字符串变量都通过stripslashes和htmlspecialchars传递

我尝试过用记号将列名括起来,但没有任何区别,所以我删除了它们

if ($nameErr == "" && $passErr == "") {
    $ok = false;
    if ($type == "Edit") {
        echo "In Edit  : ";
        echo "variables: ".$username.", ". $userlevel.", ".$edit_id;
        $stmt = $conn->prepare('UPDATE admin SET username = ?, level= ? WHERE admin_id = ? LIMIT 1');
        echo " - statement prepared";
        $stmt->bind_param('sii', $username, $userlevel, $edit_id);
        echo " - binding successful";
        $stmt->execute();
        echo " - executed";
        $ok = true;
        /*
        $stmt->bind_param('sii', $username, $userlevel, $edit_id);
        if (
                $stmt &&
                $stmt->bind_param('sii', $username, $userlevel, $edit_id) &&
                $stmt->execute()) {
            $ok = true;
        }
         */
    } else {
        $hashpw = password_hash($password, PASSWORD_DEFAULT);
        $stmt = $conn->prepare('INSERT INTO admin (username, password, level) VALUES (?, ?, ?)');
        if (
                $stmt &&
                $stmt->bind_param('ssi', $username, $hashpw, $userlevel) &&
                $stmt->execute()) {
            $ok = true;
        }
    }
    if ($ok) {
        header('location: users.php');
    } else {
        die(htmlspecialchars($conn->error));
    }
}
echo跟踪给出:In Edit:variables:admin,5,1-statement prepared 接着是致命错误:在第67行消息的C:\wamp64\www\AGC\user\u edit.php中调用布尔值上的成员函数bind_param。第67行是$stmt->bind_参数'sii',$username,$userlevel,$edit_id;线

如上所述,INSERT语句有效-更新失败。

排序

出于纯粹的绝望,我插入了一个$stmt->close;if$type==Edit{line之前的一行,我不再得到错误

我可以理解为什么如果之前有一个$stmt调用,它会起作用,但实际上没有。我也不知道为什么它会起作用,因为没有带有INSERT结构的close语句