我面臨一個問題,在我的PHP文件中,錯誤來自第三條語句中的參數,但我無法找到哪裏是嗎。這裏是我的PHP文件:PHP錯誤:mysqli_stmt_bind_param()變量數量不匹配準備語句中的參數數量
$client = "test";
$resto = "test";
$st1 = mysqli_query($con, "SELECT client_id FROM Clients WHERE email = '$client'");
$res1 = mysqli_fetch_array($st1);
$clientID = $res1["client_id"];
echo "CLIENT ID = ";
echo $clientID;
$st2 = mysqli_query($con, "SELECT restaurant_id FROM Restaurants WHERE email = '$resto'");
$res2 = mysqli_fetch_array($st2);
$restaurantID = $res2["restaurant_id"];
echo "RESTO ID = ";
echo $restaurantID;
$statement = mysqli_prepare($con, "INSERT INTO reservations (resto_id, client_id) VALUES ($restaurantID,$clientID)");
mysqli_stmt_bind_param($statement,"ii",$restaurantID,$clientID);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
非常感謝您的幫助。
答:你不使用的佔位符。 RT \ * F。 http://php.net/manual/en/mysqli.prepare.php –
非常感謝您的支持,您能更準確地瞭解我應該怎麼做才能解決問題? –
'$ restaurantID,$ clientID'應該是佔位符,而不是變量,然後綁定它們。還可以在任何地方使用參數化查詢,而不僅限於'insert'。 – chris85