0

I'm new to PHP, I need some help here. I have created a form called Home.php which accepts ID,name & file upload as inputs and it adds into mysql. Its adding successfully. I want to perform update operation so that if a user wants to update any of the fields. So what I want is it has to update these 3 fields in db. But I'm getting a following error in Process.php.

Error : Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

Here's the relevant part of my code:

$sql = "UPDATE info SET id=?, name=?, upload=? WHERE id=?";
if(!($stmt = $mysqli->prepare($sql)))
{
  die("Unable to prepare statement");
}
else
{
  $stmt->bind_param("iss", $id, $name, $upload);    
  if($stmt->execute())
  {
    echo "Successfully updated";
  }
  else
  {
    die("Update failed");
  }
}
0

2 Answers 2

3

You have 4 parameters needed for

$sql = "UPDATE info SET id=?, name=?, upload=? WHERE id=?";

Even if id should be the same, since you didn't give it name, you have to add it 2 times in your binding

$stmt->bind_param("issi", $id, $name, $upload, $id);

should work

You should check about adding named params in statements to avoid it.

Sign up to request clarification or add additional context in comments.

Comments

0

this error is due to

 $sql = "UPDATE info SET id=?, name=?, upload=? WHERE id=?";

here in this query have bind 4 parameter

but in you bind only 3 param

$stmt->bind_param("iss", $id, $name, $upload); 

here it should be

$stmt->bind_param("issi", $id, $name, $upload,$id); 

AS per our discussion your final query would be

$sql = "UPDATE info name=?, upload=? WHERE id=?";
$stmt->bind_param("ssi",  $name, $upload,$id);

9 Comments

I tried this and now the error gone, but file is uploading to the DOC folder. Simply it is showing message that successfully updated but its not updating.
@mak error gone it means this ans working fine for you. Now check you update query . Try to print your query and check what is the problem
How to do that using var_dump?
Yeah I did that. Successfully updated object(mysqli_stmt)[2] public 'affected_rows' => int 1 public 'insert_id' => int 0 public 'num_rows' => int 0 public 'param_count' => int 4 public 'field_count' => int 0 public 'errno' => int 0 public 'error' => string '' (length=0) public 'error_list' => array (size=0) empty public 'sqlstate' => string '00000' (length=5) public 'id' => int 1 File is uploaded successfully...
I'm waiting for your reply.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.