I have a form that retrieves multiple rows of data, each item has a text area for users to comment on a specific item. The number of items returned is variable, and they do not have to leave comments in any/all boxes.
<textarea name="comment[]" cols="25" rows="2"><?php echo $f2; ?></textarea> <input name="tableid[]" type="hidden" value="<?php echo $f1; ?>">
The echo statement fills the text area with whatever is currently stored in the database, because the user can modify what others have entered.
When it is passed to the form processing page, it will return this..
Submit: Submit comment: Test Comment 1,Test Comment 2 tableid: 590,591
So it seems to be passing the array correctly. I am using this code to update database
$conn = new PDO("mysql:host=xxxx;dbname=xxxxx",$username,$password); $i = 0; if(isset($_POST['submit'])) { foreach($_POST['comment'] as $comment) { $comment = $_POST['comment'][$i]; $id = $_POST['tableid'][$i]; $stmt = $conn->prepare("UPDATE reservations SET comment=:comment WHERE tableid=:id"); $stmt->bindValue(':comment', $comment, PDO::PARAM_INT); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); $i++; } }
However, this doesn't seem to be updated at all, where did I go wrong?
Thank you so much
A few things:
PDOException
when an error occurs. This will make debugging easier.Code: