After checking all the other stackoverflow, google posts with the same problem, cannot find the solution.
I am using pdo and php and I'm trying to Update the entries in a table. Could be the problem on other part of the code, but looks like some issue with the MYSQL.
Here the full message;
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i
n your SQL syntax; check the manual that corresponds to your MariaDB server vers
ion for the right syntax to use near '('eggs','scrambled') WHERE (test@12.com)' at line 1<
/pre>
My code:
Insert.php
public function newInputs(array $input_data) {
$this->db->update('cli',
[
'Food' => $input_data['newfood'],
'Comment' =>$input_data['newcomment']
] ,
[
'email' =>$input_data['email']
]);
echo "Data updated";
}
Database.php
public function update(string $table, array $data, array $where){
// array_keys(Returns all the keys of an array)
$keys = array_keys($data);
$placeholders = preg_filter('/^/', ':', $keys);
# $email = preg_filter('/^/', ':', $data['email']);
try {
$query = $this->conn->prepare("UPDATE $table SET (" . implode(',', $placeholders) . ") WHERE (" . implode(',', $where) . ")");
$query->execute($data);
} catch (PDOException $e) {
die("<pre>" . $e->getMessage() . "</pre>");
}
}
Getting closer