2015-07-20 104 views
1

我得到一個錯誤,在我寫一份書面聲明...錯誤與綁定變量

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)); 
    } 
+1

U綁定3 ... sss – Drew

回答

0

mysqli_stmt :: bind_param - mysqli_stmt_bind_param - 綁定變量來一份聲明作爲參數

因此,在你bind_param,你需要插入5個參數。

0

我解決了這個問題。我試圖綁定NOW()字段。我將代碼行更改爲..

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

它現在完美工作。