|
PHP: Edit Multiple Items/Rows and Update Button
What is the best way to add the ability to edit the field called equipPrice for multiple records and click the Update button? Note the Update button is being used for deleting checked items as well. Thank you so much for any help/advice.
<?php
// Connect to database
...
// If the form was submitted, delete the items selected from the database
if ($_POST["deleted_items"]) {
$deleted_items = join(', ', $_POST["deleted_items"]);
$query1 = "DELETE FROM equipment WHERE $equipID IN ($deleted_items)";
$result1 = @mysql_query($query1);
header("Location: index.php");
}
// Build query to fetch items from database
$query2 = "SELECT * FROM equipment ORDER BY $sortOrder";
// Execute query
$result2 = @mysql_query($query2);
// If query was okay AND we have at least 1 item...
if ($result2 && @mysql_num_rows($result2) > 0) {
print "<form action=\"index.php\" method=\"post\" target=\"main\">\n";
print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"8\">\n";
// For each item returned from query...
while($row2 = mysql_fetch_array($result2)) {
print "<tr bgcolor=\"$row_color\">\n";
print "<td align=\"center\" valign=\"middle\"><input type=\"checkbox\" name=\"deleted_items[]\" value=\"" . stripslashes($row2['equipID']) . "\"></td>\n";
...
print "<td class=\"tiny\" align=\"left\" valign=\"middle\" nowrap>$<input type=\"text\" name=\"equipPrice\" value=\"" . stripslashes($row2['equipPrice']) . "\" size=\"8\"></td>\n";
print "</tr>\n";
}
print "</table>\n";
print "<br>\n";
print "<input type=\"submit\" value=\"Update\">\n";
print "</form>\n";
} else {
...
// Close link to MySQL server
mysql_close($link);
?>
|