Jump to content

"The number of variables must match the number of parameters in a prepared statement"


Go to solution Solved by Ronbo51,

Recommended Posts

I wrote a php script to update information in an mysqli database table and and am getting the error: The number of variables must match the number of parameters in a prepared statement.

This  is the  code snippet with the error line in bold red.  I don't see anything wrong with it but hopefully some of you sharp eyed people can help me.

include "churchdb_data.php";
$con=mysqli_connect('localhost',$username,$password,$database);
if (mysqli_connect_errno()) {
  die ("Failed to connect to MySQL: " . mysqli_connect_error());
}

$sql = "UPDATE missionaries SET ID=?, missionary=?, active=?, country=?, city=?, state=?, zip=?, street=?, phone=?,email=?,
website=?, facebook=?, photo=? WHERE ID=?";
$stmt = $con->prepare($sql);


$stmt->bind_param("issssssssssss", $id, $missionary,$active,$country,$city,$state,$zip,$street,$phone,$email,$website,$facebook,$photo);

if ($stmt->execute()) {
    echo "Record updated successfully!";
} else {
    echo "Error updating record: " . $stmt->error;
}

$stmt->close();
$con->close();
?>

 

 

Edited by requinix
edited title
  • requinix changed the title to "The number of variables must match the number of parameters in a prepared statement"

You forgot the variable for the "WHERE ID=?" at the end of the query.

And are you sure you really mean to try to update the ID? That would be weird...

  • Solution

Thank you very much requinix for your quick reply and help.  I changed the code to what is shown below and now it works.

$sql = "UPDATE missionaries SET missionary=?, active=?, country=?, city=?, state=?, zip=?, street=?, phone=?,email=?,
website=?, facebook=?, photo=? WHERE ID=?";
$stmt = $con->prepare($sql);
$stmt->bind_param("ssssssssssssi", $missionary,$active,$country,$city,$state,$zip,$street,$phone,$email,$website,$facebook,$photo,$id);
I definitely do not to change the ID.  The ID input statement is type=hidden so it can't be changed.  I thought I had to include it but I now see that I don't have to.  This prepared statement programing is all new to me and you have helped me a lot.  Thanks again.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.