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));
}
SET Name='?', Cate_id='?', Price='?', Image='?' etc
does not need quotes in the ?
should be
SET Name=?, Cate_id=?, Price=?, Image=? etc...
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.