Jump to content

Mass Delete


Daney11

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/92636-mass-delete/
Share on other sites

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....

Link to comment
https://forums.phpfreaks.com/topic/92636-mass-delete/#findComment-474766
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/92636-mass-delete/#findComment-475129
Share on other sites

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";

}

}

}

Link to comment
https://forums.phpfreaks.com/topic/92636-mass-delete/#findComment-475458
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.