2
I made a code to update some columns of my record when needed. There are 7 columns listed on array
, but usually I will only update 1 or 2 columns. With this code I can update my record, but I have to put data in all the inputs
, in case I could not write something on input name="keywords"
and click on SUBMIT
and leave the others inputs
blank, because if I do this will only update the column keywords
and leave the rest of the columns blank.
So I wanted to know: How do I update one column without affecting the 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>
I found a way, I don’t know if it’s the best way but it’s a way that with me turned round!!! :-)
– user60252
LET ME ETENDER FRIEND, YOU WANT TO UPDATE ONLY THE COLUMN THAT WAS WRITTEN. IS IT ? Without having to fill everything. Just to fill in?
– Risk
@Scratched and scratched Yes
– mario
LEO JA ANSWERED FRIEND. COPY HIS CODE!
– Risk
Find it interesting with
jquery
can post on the reply. http://kithomepage.com/sos/foreach-colunas-valores-para-insert-jquery.php– user60252