I have this code to update my record and to check if there's any value on the respective input
. But it's not even updating my record, and i got this error when i click on submit:
Fatal error: 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 '? = ':title', ? = ':keywords' WHERE title = ?'
if(isset($_POST["updateBTN"])){
$insert_data = array(
'keywords' => $_POST['keywords'],
'img' => $_POST['img'],
'widht' => $_POST['widht'],
'status' => $_POST['status'],
'name' => $_POST['name'],
'height' => $_POST['height']
);
$sets="";
foreach ($insert_data as $column => $value) {
if ($value!=""){
$sets .= $column." = '".$column."', ";
}
}
$sets = rtrim($sets, ', ');
$query = "UPDATE table SET $sets WHERE title = :title";
$stmt = $conn->prepare($query);
$stmt->execute($insert_data);
}
html:
<form method="post">
<div>
<input type="text" name="title">
<span data-placeholder="Title"></span>
</div>
<div>
<input type="text" name="keywords">
<span data-placeholder="keywords"></span>
</div>
<div>
<input type="text" name="img">
<span data-placeholder="img"></span>
</div>
.
.
.
<button type="submit" name="updateBTN">Send</button>
</form>