beansandsausages Posted May 28, 2008 Share Posted May 28, 2008 Good morning Freaks, I have a small script to check and delete a check box, or multiple check boxe's, But the problem is its doing nothing, its geting the data but then not deleteing it, the codes below : $sql = "SELECT * FROM `post_box` WHERE `to_id`='{$id}' ORDER BY id DESC "; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "<h5>You have no messages messages at all to read</h5>. <p><br /><a href=?action=>Back</a></div>"; exit; } while ($row = mysql_fetch_assoc($result)) { echo " <form method=\"post\" action=\"\" /> <input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$row['id']}\" /> {$row['message']} <br /> } echo " <input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\" /> "; if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM `post_box` WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } When i lookin the source code its correct it shows the : <input name="checkbox[]" type="checkbox" id="checkbox[]" value="3" /> Message 3 <br /> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="2" /> Message 2 <br /> <input name="checkbox[]" type="checkbox" id="checkbox[]" value="1" /> Message 1 <br /> Just when i click a check box and hit delete nothing happens ?? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/107579-solved-form-error/ Share on other sites More sharing options...
beansandsausages Posted May 28, 2008 Author Share Posted May 28, 2008 Fixed it, HAHA took a hammer to my laptop and said sum nasty things to it untill it worked Quote Link to comment https://forums.phpfreaks.com/topic/107579-solved-form-error/#findComment-551426 Share on other sites More sharing options...
GingerRobot Posted May 28, 2008 Share Posted May 28, 2008 Well i see you fixed, so good stuff. However, i'd already typed this out so ill post anyway as there are a couple of points you might want to think about. 1.) Always debug your queries with mysql_error if you're having troubles. 2.) You dont need to execute a separate query to delete each item. implode the ids and use the IN clause: $del_ids = implode(',',$_POST['checkbox']); mysql_query("DELETE FROM `post_box` WHERE id IN ($del_ids)") or die(mysql_error()); 3.) Do you ever extract the variables from the $_POST array? Or are you relying on register_globals? 4.) Looks like the error is one of script logic. You output the checkboxes, then delete those which were previously selected. End result: the checkboxes are deleted, but you dont notice till you refresh the page. Quote Link to comment https://forums.phpfreaks.com/topic/107579-solved-form-error/#findComment-551433 Share on other sites More sharing options...
beansandsausages Posted May 28, 2008 Author Share Posted May 28, 2008 i ended up using implode and ended up with sum thing along the lines of your example thank you Quote Link to comment https://forums.phpfreaks.com/topic/107579-solved-form-error/#findComment-551436 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.