绑定变量出错


Error with binding variables

我正在编写的准备好的语句中出现错误…

 Number of elements in type definition string doesn't match number of bind variables on line 33. Create Topic Insert bind_param() failed:

我唯一能想到的是因为NOW()字段,但我认为不需要为此设置变量?

是否有一些东西我在这明显缺失或什么可能导致这个错误?

//Prepared INSERT stmt for the forum topic
    $stmt = $con->prepare("INSERT INTO forum_topics (`category_id`, `topic_title`, `topic_creator`, `topic_date`, `topic_reply_date`) 
    VALUES(?, ?, ?, NOW(), NOW())");
    if ( !$stmt || $con->error ) {
        die('Create Topic Insert prepare() failed: ' . htmlspecialchars($con->error));
    }
    if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {
        die('Create Topic Insert bind_param() failed: ' . htmlspecialchars($stmt->error));
    }
    if(!$stmt->execute()) {
        die('Create Topic Insert execute() failed: ' . htmlspecialchars($stmt->error));
    }

mysqli_stmt::bind_param——mysqli_stmt_bind_param -将变量作为参数绑定到准备好的语句

在你的bind_param中,你需要插入5个参数

我解决了这个问题。我试图绑定NOW()字段。我将代码行改为…

  if(!$stmt->bind_param('sssii', $cid, $title, $creator)) {