Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/107579-solved-form-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/107579-solved-form-error/#findComment-551433
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.