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

时间:2014-01-23 12:52:39

标签: php mysql

为什么我收到以下错误?代码工作,并像它应该更新数据库它只是给我这个错误。我对PHP很陌生,所以请原谅我无知。

  

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

这是我的代码:

<?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.';
    }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您忘记将 $id 绑定为参数。

$stmt->bind_param('ssssi', $p_submit, $t_submit, $check_submit, $paid_submit, $id);
                       ^------ (assuming id is an integer thus `i`)           ^^^------- (added)