jesushax Posted February 27, 2008 Share Posted February 27, 2008 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/93322-mutliple-checkboxes-update-mysql-on-submit/ Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/93322-mutliple-checkboxes-update-mysql-on-submit/#findComment-478045 Share on other sites More sharing options...
jesushax Posted February 27, 2008 Author Share Posted February 27, 2008 smashing thanks muchly Quote Link to comment https://forums.phpfreaks.com/topic/93322-mutliple-checkboxes-update-mysql-on-submit/#findComment-478128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.