I have a form that retrieves multiple rows of data and each item has a textarea for the user to comment on a particular item. The number of items returned is variable, and they don't have to leave comments in any/all of the boxes.
<textarea name="comment[]" cols="25" rows="2"><?php echo $f2; ?></textarea>
<input name="tableid[]" type="hidden" value="<?php echo $f1; ?>">
The echo statement populates the text area with whatever is currently stored in the database as the user can modify what someone else entered.
When this gets passed to the form handling page, it returns this..
Submit: Submit
comment: Test Comment 1,Test Comment 2
tableid: 590,591
so it appears to be passing the array correctly. I am using this code to update the 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 does not seem to update at all, where am i going wrong?
Many Thanks
PDO::PARAM_STRis probably the constant you intended to use for comment$comment = $_POST['comment'][$i];$_POST['tableid'][$i];