Hi,
I'm attempting to perform a batch action on a series of rows in a MySQL table. Ideally, what I want to happen is for a user to press an "Approve" or "Delete" button and have the script do the associated task (either approve the selected message(s) for display on the site or remove the selected message(s) entirely).
Here's the code I'm working with:
<?php
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");
}
$index = 1;
$pagetitle = "List Unapproved Items";
include("modules/Buzz/common/shared.inc");
include("header.php");
if($_POST['approve'] && isset($_POST['selected'])){
$selected_ids = implode(',', $_POST['selected']);
$sql = "UPDATE ub_items
SET cleared = 'YES'
WHERE itemid IN ($selected_ids)";
sql_query($sql, $dbi);
}
if($_POST['delete'] && isset($_POST['selected'])){
$selected_ids = implode(',', $_POST['selected']);
$sql = "DELETE FROM ub_items
WHERE itemid IN ($selected_ids)";
sql_query($sql, $dbi);
}
OpenTable();
?>
<table border="0" width="500" cellspacing="0" cellpadding="0">
<tr>
<td align="left" width="360">
<form name="report" method="POST" action="modules.php?name=Buzz&file=report">
Project:
<?php
$sql = "SELECT proj_name, pid
FROM ub_project
WHERE status='active'
ORDER BY proj_name";
$projects = idNametoArray($sql);
echo mysql_error();
$proj_select['ALL'] = 'All';
$proj_select['NONE'] = '--';
foreach($projects as $k => $v) $proj_select[$k] = $v;
echo arrayToSelect($proj_select, "projid", $_POST['projid']);
?>
<input name="go" type="submit" value="Go">
</form>
</td>
<td align="right" width="70">
<input name="approve" type="submit" value="Approve">
</td>
<td align="right" width="70">
<input name="delete" type="submit" value="Delete"
onclick="return confirm('Are you sure you want to delete these activities?');">
</td>
</tr>
</form>
</table>
I think I may have the FORM tag in the wrong place, but I really don't know where to start. Again, I want a site admin to be able to check selected messages and perform a batch action on them -- either approve or delete and have the database respond accordingly.
Thanks for any help!
Jim