mnewbegin Posted December 29, 2009 Share Posted December 29, 2009 Can I use a single checkbox to delete records and update mysql records ? using 2 submit buttons on the page? one for delete, and one for update but using the same single checkbox? for each record Here is my whole page code that works.. it deletes multiple records from the database, and displays inventory on the screen and counts of items, but I want to update items to flag them for the current order for my pending.php page. do i need a new set of checkboxes and a code to update $pending to 1 instead of 0 which means not pending on a order? <?php session_start(); include 'dbc.php'; if (!isset($_SESSION['user'])) { die ("Access Denied"); } ?> <style type="text/css"> <!-- .style1 { color: #FFFFFF; font-weight: bold; } --> </style> <h2><b>Inventory</b> </h2> <?php if (isset($_SESSION['user'])) { ?> <p>Logged as <?php echo $_SESSION['user']; ?> | <a href="settings.php">Settings</a> | <a href="logout.php">Logout</a> </p> <?php //connect to database $sql="SELECT * FROM _products ORDER BY productID ASC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <link href="styles.css" rel="stylesheet" type="text/css"> <center> <p> </p> <p><a href="insert.php">| Insert NEW Product</a> <a href="addcustomer.php"> | Add Customer |</a><a href="viewcustomer.php"> View Customers |</a> <a href="pending.php"> Pending Inventory |</a> </p> <table width="700" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="700" border="1" cellspacing="0" cellpadding="3"> <tr> <form name="form1" method="post" action=""> <td height="52" colspan="9" bgcolor="#d5e8f9" class="mnuheader"><div align="center"><strong><br><h3>Inventory</h3> </strong></div></td> </tr> <tr> <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">#</span></td> <td bgcolor="#74889b" class="mnubody" align="center"><span class="style1">ID:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Number:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Desc:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Count#:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Customer:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Pending:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Received:</strong></td> <td bgcolor="#74889b" class="mnubody" align="center"><strong class="style1">Update:</strong></td> </tr> <?php for($a; $a < mysql_num_rows($result); $a++) { $rows = mysql_fetch_array($result); echo ($a % 2 == 0) ? '<tr>' : '<tr class="altrow">' . "\n"; ?> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['productID']; ?>"></td> <td><? echo $rows['productID']; ?></td> <td><? echo $rows['productNum']; ?></td> <td> <? echo $rows['productDesc']; ?></td> <td><? echo $rows['productCount']; ?></td> <td><? echo $rows['customer']; ?></td> <td><? echo $rows['pending']; ?></td> <td><? echo $rows['dateRcvd']; ?></td> <td align="center"><a href="update.php?productID=<? echo $rows['productID']; ?>">EDIT</a></td> </tr> <?php } ?> <?php } ?> <tr> <td colspan="9" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM _products WHERE productID='$del_id'"; $result = mysql_query($sql); } // if successful redirect to inv_main.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"1;URL=inv_main.php\">"; } } ?> </table> </form> </td> </tr> </table> </center> <?php mysql_close(); ?> Here is the current working multiple delete boxes. <tr> <td colspan="9" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM _products WHERE productID='$del_id'"; $result = mysql_query($sql); } // if successful redirect to inv_main.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"1;URL=inv_main.php\">"; } } ?> Link to comment https://forums.phpfreaks.com/topic/186556-can-i-use-a-single-checkbox-to-update-and-delete-mutliple-mysql-records/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.