Jump to content

[SOLVED] delete more than one checkbox if selected


contra10

Recommended Posts

in my inbox if i select more than one checkbox, all of the ones selected don't delete at one time...only one gets deleted at a time here is my code

<?php
		mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());


 $friendq= "SELECT * FROM inbox WHERE recusername = '$username' ORDER BY iid DESC";
$friendnames = mysql_query($friendq) or die(mysql_error());

while($friend = mysql_fetch_array($friendnames)) 
{ 
$friendid= "{$friend['sendid']}";
$friendusername= "{$friend['recusername']}";
	$sendingusername= "{$friend['sendusername']}";
$date= "{$friend['date']}";
$title= "{$friend['title']}";
	$msgid= "{$friend['iid']}";
 	$colorvalue= "{$friend['value']}"; 
$recievingid="{$friend['recid']}"; 

$bgcc=1;

	echo "<tr>";
	echo"<td><Input type = 'Checkbox' Name ='checkbox' value ='$msgid'></td>";
 echo "<td align='left' width='10%' height='50'>";
echo"<a href ='http://localhost/profile/index.php?user=$friendid' ><img src='http://localhost/image/imagereplace.php?id=$friendid'></a>";
  echo "</td>";
	if ($bgcc == $colorvalue){
	echo"<td width= '90%' align='center' bgcolor='#DEDAD7'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}else{
		echo"<td width= '90%' align='center' bgcolor='black'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}
	echo"<FONT FACE='ariel' SIZE='3' color='#0094f7'><b>$title<br><br></font></td></tr>";
	echo "<tr><td></td><td></td>";
	echo "<td align='right' bgcolor='#DEDAD7'><FONT FACE='ariel' SIZE='2' color='#0094f7'>Sent by <b>$sendingusername</b> on $date</font></a></td>";
echo "</tr>";
}

?>
<?php

// Post Edit: Might want to connect to mysql, you MUST be conected to mysql before you call mysql_escape_String or mysql_real_escape_String.
$ch = mysql_connect("localhost","root","");

// If there is a form being submitted?
if(isset($_POST['checkbox']) && isset($_POST['delete'])){

// Santize this client input?
$checkboxid = mysql_real_escape_string($_POST['checkbox']);

// Execute and store the mysql result resource
$result = mysql_query("DELETE FROM `inbox` WHERE `iid`='".$checkboxid."'") or die(mysql_error());

// Execute the mysql query and store the result resource
$result = mysql_query("SELECT `recid` FROM `inbox` WHERE `recid` = '".$id."'") or die(mysql_error());

// Loop each result row
while($row = mysql_fetch_array($result,MYSQL_BOTH)){
	$rep = $row['recusername'];
}

// Create the URL string
$url = "http://localhost/inbox/"; // Should this be $rep ?????

// Finall Echo the meta tag
echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">');
}
?>

<input type="submit" name="delete" value="delete">
</table>
</form>

Link to comment
Share on other sites

change this:

echo"<td><Input type = 'Checkbox' Name ='checkbox' value ='$msgid'></td>";

to

echo"<td><Input type = 'Checkbox' Name ='checkbox[]' value ='$msgid'></td>";

 

and then add a loop:

<?php

// Post Edit: Might want to connect to mysql, you MUST be conected to mysql before you call mysql_escape_String or mysql_real_escape_String.
$ch = mysql_connect("localhost","root","");

// If there is a form being submitted?
if(isset($_POST['checkbox']) && isset($_POST['delete'])){
   // Loop
   foreach($_POST['checkbox'] as $msgid){

      // Santize this client input?
      $checkboxid = mysql_real_escape_string($msgid);
   
      // Execute and store the mysql result resource
      $result = mysql_query("DELETE FROM `inbox` WHERE `iid`='".$checkboxid."'") or die(mysql_error());
   }
   
   // Execute the mysql query and store the result resource
   $result = mysql_query("SELECT `recid` FROM `inbox` WHERE `recid` = '".$id."'") or die(mysql_error());

   // Loop each result row
   while($row = mysql_fetch_array($result,MYSQL_BOTH)){
      $rep = $row['recusername'];
   }
   
   // Create the URL string
   $url = "http://localhost/inbox/"; // Should this be $rep ?????
   
   // Finall Echo the meta tag
   echo('<meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'">');
   }
?>

Link to comment
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.