Gazz1982 Posted May 2, 2009 Share Posted May 2, 2009 Here is my code while($row = mysql_fetch_array($result2)) { echo "<form class='small' name='login' method='post' action='delete.php?<?php echo SID?>'>"; echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='delete' value='$del' /></td>"; echo "<td>" . $row['NAME_FIRST'] . "</td>"; echo "<td>" . $row['NAME_LAST'] . "</td>"; echo "<td>" . $row['EMAIL'] . "</td>"; echo "<td>" . $row['PASSWORD'] . "</td>"; echo "<td>" . $row['COMPANY'] . "</td>"; echo "<td>" . $row['ADDRESS1'] . "</td>"; echo "<td>" . $row['ADDRESS2'] . "</td>"; echo "<td>" . $row['ADDRESS3'] . "</td>"; echo "<td>" . $row['COUNTY'] . "</td>"; echo "<td>" . $row['COUNTRY'] . "</td>"; echo "<td>" . $row['POST_CODE'] . "</td>"; echo "<td>" . $row['PHONE'] . "</td>"; echo "<td>" . $row['VALIDATE'] . "</td>"; echo "<input type='checkbox' name='validate' value='$val' /></td>"; echo "<td>" . $row['ID'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "<input type='submit' name='Submit' value='delete' />"; echo "<input type='submit' name='Submit' value='validate' />"; echo "</form>"; A php generated table which loops through my database which lists everything from the database table. Also it has two sets of check boxes. 1. I want it so that when the delete checkbox is selected and the delete button is clicked it deletes this entry from the database. 2. There is a 2nd checkbox $val I want when this is checked and the validate button pressed, for the check box to stay checked and the entry in the validate colum to say 'yes' when unchecked to say 'no' default value 'no' All help is much appreciated Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/ Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 1) <input type="checkbox" name="delete" value="1" /> <?php if (sizeof($_POST) && isset($_POST['delete']) && $_POST['delete'] === 1) { ..delete entry.. } 2) Use the hidden value technique <input type="hidden" name="validate" value="no" /> <input type="checkbox" name="validate" value="yes" /> when checked will say yes if not will say no Quote Link to comment https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/#findComment-824080 Share on other sites More sharing options...
Gazz1982 Posted May 2, 2009 Author Share Posted May 2, 2009 I need it to update the database too with either yes or no, so update table name SET validate=yes where ID = $(the checked boxes) and update table name SET validate=no where ID = $(the checked boxes) also where in my code do I put input type="checkbox" name="delete" value="1" /> <?php if (sizeof($_POST) && isset($_POST['delete']) && $_POST['delete'] === 1) { ..delete entry.. } Sorry I'm an annoying newbee! Quote Link to comment https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/#findComment-824084 Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 add another field in your form which says: <input type="hidden" name="id" value="<?php print $row['id']; ?>" /> then you can do: UPDATE tableName SET validate = $_POST['validate'] WHERE id = $_POST['id'] also where in my code do I put well that is more difficult, not in the while that is for certain Sorry I'm an annoying newbee! And i am here to entertain you Quote Link to comment https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/#findComment-824093 Share on other sites More sharing options...
Gazz1982 Posted May 2, 2009 Author Share Posted May 2, 2009 Ok, I'm still having problems with deleting from my db through php code: //Delete the customer rows (only if the form has been submitted) if (isset($_POST['submit'])) { foreach ($_POST['todelete'] as $delete_id) { $query="DELETE FROM login WHERE ID = $delete_id"; mysql_query($query) or die ('Error in query: ' .mysql_errno() . mysql_error()); } echo 'Customer(s) removed.<br />'; } echo"<form>"; // Display the customer rows with checkboxes for deleting $query="SELECT * FROM login"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo '<input type="checkbox" value="' . $row['id'] .'"name="todelete[]" />'; echo $row['NAME_FIRST']; echo ' '.$row['NAME_LAST']; echo ' '.$row['EMAIL']; echo '<br />'; } echo "<input type='submit' name='submit' value='submit' />"; echo "</form>"; displays fine but does not do anything! Quote Link to comment https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/#findComment-824112 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.