I have a form which lists a list of records from my database.
I would like to check the boxes of any records I want to update becuase the field i want to update all has the same value
I can't get them to update and need some help
here is my form
echo '<form name="archive-form" action="'.$_SERVER['REQUEST_URI'].'" method="post">';
// Iterate through the results
$i = 0;
while ($row = $result->fetch()) {
echo "<p><input type='checkbox' name='id[$i]' value='{$row['id']}' />{$row['title']}</p>"
$i++;
}
echo "<input type='submit' value='submit' name='archive' />";
echo "</form>";
and the function that is called when the form is submitted
if ( isset ($_POST['archive']) ) {
$id = $_POST['id'][$i];
$result = content_archive('articles', 'archived', 'title', $id);
and the function that should so the update
function content_archive($table, $field1, $field2, $content_title) {
global $host,$dbUser,$dbPass,$dbName;
require_once("../php/database/connection.php");
require_once("../php/database/MySQL.php");
// Connect to the database and grab the email
$db = & new MySQL($host,$dbUser,$dbPass,$dbName);
// find out how many records there are to update
$size = count($_POST['id']);
// start a loop in order to update each record
$i = 0;
while ($i < $size) {
$sql="UPDATE $table SET $field1='y' WHERE $field2=$content_title' LIMIT 1";
//query to enter form data into database
$result = $db->query($sql);
$i++;
}
if(!$result) {
return 'There has been an error adding to the database. Please consult Adam and advise of the problem';
}
else {
return 'Correct';
}
}
I am not sure bu ti don't know if i am passing an array of ids to the fnction so it can do the update on each record