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
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
Share on other sites

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

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