Jump to content

mutliple checkboxes update mysql on submit


jesushax

Recommended Posts

Hi all below is my code

 

what im trying to do when action is archive, is to set all the records with tick in the checkbox with the field NewsArchive set to 1

 

any help much appreciated

 

Cheers

 

<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_header.php');

switch(@$_GET["action"]) {
Case "delete":

$NewsID = $_GET["ID"];

mysql_query("DELETE FROM tblNews Where NewsID='".$NewsID."'") or die(mysql_error());
header("Location: /admin/edit_news_list.php");
break;

Case "archive";


break;
Default:
echo "<p>Edit, Archive and Delete News Records using the below navigation.</p>";

$NewsSQL = mysql_query("SELECT * FROM tblNews Where NewsArchive='0' ORDER BY NewsDateAdded DESC") or die(mysql_error());

echo '<form id="archive" method="post" action="edit_news_list.php?action=archive">'."\n";
echo '<table width="80%"><tr style="font-weight:bold;"><td>News Title</td><td>Date Added</td><td>Date Modified</td><td>Edit</td><td>Archive</td><td>Delete</td></tr>'."\n";

while ($rsNews = mysql_fetch_array($NewsSQL)) {

echo "<tr><td>";
echo $rsNews["NewsTitle"]."</td><td>";
echo $rsNews["NewsDateAdded"]."</td><td>";
if (empty($rsNews["NewsDateModified"])) {
echo " "; }
else {
echo $rsNews["NewsDateModified"];
}
echo '</td><td><a href="/admin/edit_news.php?ID='.$rsNews["NewsID"].' ">edit</a></td>';
echo "<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"".$rsNews['NewsID']." \"></td>";
echo '<td><a href="?action=delete&ID='.$rsNews["NewsID"].' ">delete</a></td>';
echo "</tr>"."\n";
} 
echo ' <tr style="height:50px;"><td colspan="6" style="text-align:right;"><input type="submit" value="Add Records to Archive" /></td></tr> ';
echo "</table></form>";
}
include($_SERVER['DOCUMENT_ROOT'] . '/includes/admin_footer.php');

?> 

should look something like this:

 

Case "archive";
if(is_array($_POST['checkbox'])){
  foreach($_POST['checkbox'] as $NewsID){
    mysql_query("UPDATE tblNews SET NewsArchive = 1 WHERE NewsID='".$NewsID."'") or die(mysql_error());
  }
}
header("Location: /admin/edit_news_list.php");
break;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.