Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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 更新mysql数据库中的记录时,bind_param()出错_Php_Mysql - Fatal编程技术网

Php 更新mysql数据库中的记录时,bind_param()出错

Php 更新mysql数据库中的记录时,bind_param()出错,php,mysql,Php,Mysql,为什么我会得到下面的错误?代码可以工作,并更新数据库,就像它应该给我这个错误一样。我是PHP新手,请原谅我的无知 mysqli_stmt::bind_param[mysqli stmt.bind param]:数量 变量与准备语句中的参数数不匹配 这是我的代码: <?php require_once('connection.inc.php'); $conn = dbConnect('write'); // prepare SQL statement $sq

为什么我会得到下面的错误?代码可以工作,并更新数据库,就像它应该给我这个错误一样。我是PHP新手,请原谅我的无知

mysqli_stmt::bind_param[mysqli stmt.bind param]:数量 变量与准备语句中的参数数不匹配

这是我的代码:

<?php
    require_once('connection.inc.php');
    $conn = dbConnect('write');
    // prepare SQL statement 
    $sql = "UPDATE reimbursements 
                SET presidentstatus='$p_submit',
                    treasurerstatus='$t_submit', 
                    checknumber='$check_submit', 
                    paid='$paid_submit' 
            WHERE id='$id'";
    $stmt = $conn->stmt_init();
    $stmt = $conn->prepare($sql);
    // bind parameters and insert the details into the database
    $stmt->bind_param('ssss', $p_submit, $t_submit, $check_submit, $paid_submit);
    $stmt->execute();

    if ($stmt->affected_rows == 1) {
        $success = "Information has been updated.";
    } else {
        $errors[] = 'Sorry, there was a problem with the database.';
    }
谢谢您的帮助。

您忘记将$id绑定为参数。
我更改了绑定$id的代码,但它仍然给我相同的错误。表中id的数据类型是什么?数据类型是INT。我注释掉了$stmt->bind_param'ssss',$p_submit,$t_submit,$check_submit,$paid_submit;现在它工作了,我没有收到任何错误。我需要绑定参数吗?
$stmt->bind_param('ssssi', $p_submit, $t_submit, $check_submit, $paid_submit, $id);
                       ^------ (assuming id is an integer thus `i`)           ^^^------- (added)