Lie Hili Lie Hili - 1 year ago 102
PHP Question

PHP ERROR : mysqli_stmt_bind_param() Number of variables doesn't match number of parameters in prepared statement

i am facing a problem in my php file, the error is comming from the parameters in the third statement, but i can not find where is it. Here is my PHP file:

$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)");


$response = array();
$response["success"] = true;

echo json_encode($response);

Thank you in advance for your help.

Answer Source

Change your statement like bellow

$statement = mysqli_prepare($con, "INSERT INTO reservations (resto_id, client_id) VALUES ( ? , ? )");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download