cadac Posted December 4, 2011 Share Posted December 4, 2011 Hi, I need some help figuring out my problem. I currently have a script that retrieves records from a mysql database, then has checkboxes to enable to delete a record? Any help where I might be going wrong as it displays, but doesn't delete?? Thanks <?php require_once('includes/config.php'); $sql="SELECT * FROM members ORDER BY member_id"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="413" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="5" bgcolor="#FFFFFF"><strong>Delete a Member</strong> </td> </tr> <tr> <td width="48" align="center" bgcolor="#FFFFFF">#</td> <td width="42" align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td width="129" align="left" bgcolor="#FFFFFF"><strong>First Name</strong></td> <td width="152" align="left" bgcolor="#FFFFFF"><strong>Last Name</strong></td> <td width="152" align="left" bgcolor="#FFFFFF"><strong>Email</strong></td> </tr> <?php while($rows=mysql_fetch_assoc($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['member_id']; ?>"></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['member_id']; ?></td> <td align="left" bgcolor="#FFFFFF"><? echo $rows['firstname']; ?></td> <td align="left" bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="left" 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++){ $id = $checkbox[$i]; $sql = "DELETE FROM members WHERE member_id='$id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete-member.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/ Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 Do you have the following directives set in your php.ini file? If not, make those changes, save the file, restart Apache and post any errors that are returned. error_reporting = -1 display_errors = On Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/#findComment-1294391 Share on other sites More sharing options...
cadac Posted December 4, 2011 Author Share Posted December 4, 2011 I can view my php.ini file but have no control over my apache server Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/#findComment-1294394 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 It would be much easier to develop locally, using a stack such as LAMP, MAMP or WAMP. Then you wouldn't have to upload files every time you make the tiniest change. For the moment however, add the following to the top of the script, right after the opening <?php tag error_reporting(-1); ini_set('display_errors', 1); Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/#findComment-1294405 Share on other sites More sharing options...
cadac Posted December 4, 2011 Author Share Posted December 4, 2011 Thanks, worked this time Notice: Undefined variable: delete in /home/upckayju/public_html/members/admin/delete-member.php on line 102 I've looked at this and its the submit button which i changed to this: if(isset($_POST['delete'])){ but this still didn't delete a row? Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/#findComment-1294415 Share on other sites More sharing options...
cadac Posted December 4, 2011 Author Share Posted December 4, 2011 Solved, took some concentration finding out what was wrong. The checkbox value wasn't declared so it was processing it correctly <?php require_once('includes/config.php'); $sql="SELECT * FROM members ORDER BY member_id"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="413" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="5" bgcolor="#FFFFFF"><strong>Delete a Member</strong> </td> </tr> <tr> <td width="48" align="center" bgcolor="#FFFFFF">#</td> <td width="42" align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td width="129" align="left" bgcolor="#FFFFFF"><strong>First Name</strong></td> <td width="152" align="left" bgcolor="#FFFFFF"><strong>Last Name</strong></td> </tr> <?php while($rows=mysql_fetch_assoc($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['member_id']; ?>"></td> <td align="center" bgcolor="#FFFFFF"><? echo $rows['member_id']; ?></td> <td align="left" bgcolor="#FFFFFF"><? echo $rows['firstname']; ?></td> <td align="left" bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this if(isset($_POST['delete'])){ $checkbox=$_POST['checkbox']; for($i=0;$i<count($checkbox);$i++){ $id = $checkbox[$i]; $sql = "DELETE FROM members WHERE member_id='$id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ } } mysql_close(); ?> </table> </form> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/252464-delete-script-using-checkboxes/#findComment-1294426 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.