I have an update form that uses a loop to echo a list of records to be updated. It includes a text field , 'Sentences' and a checkbox, 'Acceptable'. My foreach efforts are not working and are gobbling columns of data so it is time to ask for help. Gentlemen and Ladies, how do I write this?
Thanks for your help.
<?php
if( isset($_POST["Sentences_ID"]) ) {
foreach($_POST['Sentences_ID'] as $key=>$value) {
$updateSQL = sprintf("UPDATE Sentences SET Sentences=%s, Acceptable=%s WHERE Sentences_ID=$value",
GetSQLValueString($_POST['Sentences'], "text"),
GetSQLValueString($_POST['Acceptable'], "text"),
($_POST['Sentences_ID']));
mysql_select_db($database_name, $name);
$Result1 = mysql_query($updateSQL, $name) or die(mysql_error());
}
}
?>
<?php
do {
?>
Sentence:<input type="hidden" name="Sentences_ID[]" id="Sentences_ID[< ?php echo $row_rsCounting['Sentences_Id'];?>]" value="<?php echo $row_rsCounting['Sentences_Id'];?>" />
Acceptable:<input type="checkbox" name="Acceptable" id="Acceptable" value="Acceptable"/></label> |
<input type="text" name="Sentences" id="Sentences" value="< ?php echo $row_rsCounting['Sentences'];?>" size="50" />
<?php
} while ($row_rsCounting = mysql_fetch_assoc($rsCounting));
?>
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.