I have written this function using PDO statement for updating rows in table ‘bengali’. The function is working but generating an error message. The error message is at the bottom of the topic.
public function dataUpdate(){
$id="";
$Updatefield = "";
if(isset($_POST['update'])){
$id= $_POST['id'];
$Updatefield = $_POST['Bn_Meaning'];
}
$sql = "UPDATE bengali SET Bn_Meaning ='$Updatefield' WHERE id=$id";
// Prepare statement
$stmt = $this->dbconn()->prepare($sql);
$stmt->execute();
// execute the query
echo $stmt->rowCount() . " records UPDATED successfully";
}
I called the function by creating the object as below in update.php file
<?php
$update = new GetData();
$update->dataUpdate();
?>
The error message:
: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1 in C:\xampp\htdocs\update\classes\GetData.php:56 Stack trace: #0 C:\xampp\htdocs\update\classes\GetData.php(56): PDOStatement->execute() #1 C:\xampp\htdocs\update\includes\update.php(58): GetData->dataUpdate() #2 C:\xampp\htdocs\update\index.php(18): include_once(‘C:\xampp\htdocs…’) #3 {main} thrown in C:\xampp\htdocs\update\classes\GetData.php on line 56