Daney11 Posted February 23, 2008 Share Posted February 23, 2008 Hey guys, This is my form. <form method="post" action=""> <table width="508" cellpadding="0" cellspacing="0" align="center" class="news-table"> <tr> <td width="254" height="21" bgcolor="#535459"> <a href="mail_compose.php">[Create New Mail]</a></td> <td width="254" height="21" bgcolor="#535459" align="right"><input name="delete" type="submit" id="delete" value="Delete"> </td> </tr> </table> <table width="508" cellpadding="0" cellspacing="0" align="center"> <tr> <td height="1"><img src="images/spacer.gif"></td> </tr> </table> <table width="508" cellpadding="0" cellspacing="0" border="0" align="center" class="sponsor_more-table"> <tr> <td width="20" height="21" align="left" valign="middle" class="text"> </td> <td width="100" height="21" align="left" valign="middle" class="boldtext"> From:</td> <td width="140" height="21" align="left" valign="middle" class="boldtext"> Date:</td> <td width="228" height="21" align="left" valign="middle" class="boldtext"> Subject:</td> <td width="20" height="21" align="left" valign="middle" class="text"><input name="delete_mail" type="checkbox" value="" /><input type="hidden" name="submitted" value="TRUE"></td> </tr> </table> <link href="style/layout1_style.css" rel="stylesheet"> <table width="508" height="1" cellpadding="0" cellspacing="0" border="0" align="center"> <tr> <td><img src="images/spacer.gif" height="1"></td> </tr> </table> <table width="508" cellpadding="0" cellspacing="0" border="0" align="center" class="sponsor_more-table"> <?php // Colours For Different Positions $color = '#73757b'; $color1 = '#535459'; $color = ($row_count % 2) ? $color : $color1; if ($mail_read == 'Unread') { $mail_image = '<img src="misc/new_mail.gif">'; } else { $mail_image = '<img src="misc/old_mail.gif">'; } if (strlen($mail_from) > 11 ) { $totalchars = 11; $mail_from = substr($mail_from,0,$totalchars). "..."; } ?> <tr> <td width="20" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"> <?php echo $mail_image ?></td> <td width="100" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"> <a href="member.php?member_id=<?php echo $member_id ?>"><?php echo $mail_from ?></a></td> <td width="140" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"> <?php echo $mail_date ?></td> <td width="228" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"> <a href="mail_read.php?mail_id=<?php echo $mail_id ?>"><?php echo $mail_subject ?></a></td> <td width="20" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"><input name="delete_mail[]" id="delete_mail[]" type="checkbox" value="<?php echo $mail_id ?>" /></td> </tr> </table> </form> And im using if($delete){ for($i=0;$i<$total_results;$i++){ $del_id = $delete_mail[$i]; $sql = "DELETE FROM mail WHERE mail_id='$del_id'"; $resulta = mysql_query($sql) or die(mysql_error()); } if($resulta){ echo "lol"; } } But nothing is getting deleted. Im getting no errors or nothing. The values are correct inside the checkboxes etc. the php is at the top of the script. Quote Link to comment Share on other sites More sharing options...
izbryte Posted February 23, 2008 Share Posted February 23, 2008 What about if you set up your checkboxes as an array? <input name="delete_mail[]" type="checkbox" value="" /> notice the "[]" after delete_mail Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 23, 2008 Author Share Posted February 23, 2008 <td width="20" height="21" align="left" valign="middle" class="text" bgcolor="<?php echo $color ?>"><input name="delete_mail[]" id="delete_mail[]" type="checkbox" value="<?php echo $mail_id ?>" /></td> I already did, 3rd from last line Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 23, 2008 Author Share Posted February 23, 2008 Im now using if (isset($_POST['submitted'])) { for($i=0;$i<$totalmail;$i++){ $del_id = $delete_mail[$i]; $sql = "DELETE FROM mail WHERE mail_id = '$del_id'"; $result = mysql_query($sql) or die(mysql_error()); } if($result){ echo $sql; } } With a hidden submit field and now im getting.. DELETE FROM mail WHERE mail_id = '' So the ID is not being sent, however the values of the checkboxes are correct and when i view source code the values are there.... Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 23, 2008 Author Share Posted February 23, 2008 this if (isset($_POST['submitted'])) { for($i=0;$i<$totalmail;$i++){ $del_id = $_POST[delete_mail][$i]; $sql = "DELETE FROM mail WHERE mail_id = '$del_id'"; $result = mysql_query($sql) or die(mysql_error()); } } works, thanks anyways guys Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 actaully, this still isnt working, its only allowing me to delete the top entry only. ive tested everything and even var_dumped everything. using var_dump the top entry gives me a value but the entrys below that dont give me nothing. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 ive googled some examples but get nothing what im looking for, can anyone link me to a tutorial if no one knows how to fix this? Thankyou Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 Im now using var_dump($_POST['delete_mail']); if (isset($_POST['submitted'])) { foreach ($_POST['delete_mail'][] as $del_id => $checked) { $sql = "DELETE FROM mail WHERE mail_id = '$checked'"; //$result = mysql_query($sql) or die(mysql_error()); } if($result) { echo $sql; //echo '<META HTTP-EQUIV=Refresh CONTENT="1">'; } } When i var_dump i get. array(1) { [0]=> string(2) "20" } array(2) { [0]=> string(2) "20" [1]=> NULL } I have 2 mails, mail_id 20 and mail_id 25. When i select both its not picking up the 25 in the array. When i click on mail_id 20 i get array(1) { [0]=> string(2) "20" } array(2) { [0]=> string(2) "20" [1]=> NULL } When i just click on mail_id 25 which is the bottom entry i get NULL array(1) { [0]=> NULL } Any ideas? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 Anyone got any checkbox code then can post for me to look at? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 Im sure someone from PHPFreaks knows how to mass delete from checkboxes. Quote Link to comment Share on other sites More sharing options...
balkan7 Posted February 24, 2008 Share Posted February 24, 2008 why in your code action is blank ? <form method="post" action=""> Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 Because im using a hidden field called submitted which is true. So i dont need an action in form. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 24, 2008 Author Share Posted February 24, 2008 Im using http://www.phpeasystep.com/mysqlview.php?id=8 and that is wrong, that doesnt work. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 25, 2008 Author Share Posted February 25, 2008 for the 100 people who viewed this topic and had no clue i found out agter 7 hours of testing. if($_POST['delete']){ for($i=0;$i<$total_results;$i++){ $del_id = $_POST['delete_mail'][]; $sql = "DELETE FROM mail WHERE mail_id='$del_id'"; $resulta = mysql_query($sql) or die(mysql_error()); } if($resulta){ echo "lol"; } } } Quote Link to comment 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.