Error in UPDATE function

0

I'm having this error while trying to run this update:

  

Fatal error: Uncaught exception 'PDOException' with message   'SQLSTATE [42000]: Syntax error or access violation: 1064 You have an   error in your SQL syntax; check the manual that corresponds to your   MySQL server version for the right syntax to use near 'WHERE id =' 1 ''   at line 2 'in C: \ wamp \ www \ siteOriginal \ classes \ official.php on line   65

In case the line 65 is execute, what should I be doing wrong?

public function update($id){

    $sql = "UPDATE $this->table SET cargo = :cargo, horastb = :horastb, salario = :salario, 
    WHERE id=:id";
    $stmt = DB::prepare($sql);
    $stmt->bindParam(':cargo', $this->cargo);
    $stmt->bindParam(':horastb', $this->horastb);
    $stmt->bindParam(':sa'insira o código aqui'lario', $this->salario);
    $stmt->bindParam(':id', $id);
    return $stmt->execute();
  }
    
asked by anonymous 03.06.2016 / 03:08

1 answer

0

The error is in the query. You have an extra comma before WHERE , just remove it works.

$sql = "UPDATE $this->table SET cargo = :cargo, horastb = :horastb, salario = :salario,
WHERE id=:id";

To:

$sql = "UPDATE $this->table SET cargo = :cargo, horastb = :horastb, salario = :salario 
WHERE id=:id";
    
03.06.2016 / 04:25