I made a code to update some columns of my record when I need it. There are 7 columns listed in array
, but generally I only update 1 or 2 columns. With this code I can update my registry, but I have to put data in all inputs
, in case I could not write something in input name="keywords"
and click SUBMIT
and leave the other inputs
blank, because if I do this it will only update the keywords
column and leave the rest of the columns blank.
So I wanted to know: How do I update one column without affecting others?
if(isset($_POST["updateBTN"])){
$insert_data = array(
':title' => $_POST['title'],
':keywords' => $_POST['keywords'],
':img' => $_POST['img'],
':widht' => $_POST['widht'],
':status' => $_POST['status'],
':name' => $_POST['name'],
':height' => $_POST['height']
);
$query = "UPDATE table SET keywords = :keywords, img = :img, widht = :widht, status = :status, name = :name, height = :height WHERE title = :title";
$statement = $conn->prepare($query);
$statement->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>