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');

?> 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.