0

I'm getting the following error

Warning: PDOStatement::execute(): SQLSTATE[HY093]: 
Invalid parameter number: number of bound variables does not match number of tokens

When I'm trying to update MySQL database.

Here is the code my using.

public function update() {
    global $db;
    $stmt = $db->prepare("UPDATE products SET Name='?', Cate_id='?', Price='?', Image='?', Special='?', Special_price='?', Disable='?' WHERE PID = ?;");
    $stmt->execute(array($this->name, $this->category, $this->price, $this->image, $this->special, $this->special_price, $this->disable, $this->id));
}
1
  • 1
    did you try removing ; from "UPDATE products SET Name='?', Cate_id='?', Price='?', Image='?', Special='?', Special_price='?', Disable='?' WHERE PID = ?;" and running again? i have seen issues caused by ; while binding the parameters Commented Mar 13, 2014 at 10:39

2 Answers 2

3
SET Name='?', Cate_id='?', Price='?', Image='?'  etc

does not need quotes in the ?

should be

SET Name=?, Cate_id=?, Price=?, Image=? etc...
Sign up to request clarification or add additional context in comments.

1 Comment

@meda yeah sorry about that. I was going to do it but it said I have to wait 10 minutes.
0

Please follow the following:

$stmt = $db->prepare("UPDATE products SET Name='?', Cate_id=?, Price=?, Image=?, Special=?, Special_price=?, Disable=? WHERE PID = ?;");

$stmt->bind_param($this->name, $this->category, $this->price, $this->image, $this->special, $this->special_price, $this->disable, $this->id);

$stmt->execute();

Comments

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.