Error in UPDATE function

Asked

Viewed 59 times

0

I am 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 funcionario.php on line 65

In case the line 65 is the execute, what I must 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();
  }
  • $stmt->bindParam('sainsira o código aquiLario', $this->salario); You’re not passing the name of the column, you’re passing a full description of accents.... Plus I’m not sure if the $this->table inside the variable will work. Weird.....

1 answer

0


The error is in the query. It has an extra comma before the WHERE, only remove that 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";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.