By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Delete Usings Checkboxes

100+
P: 133
Hi,

I have a system in place like an inbox which people can select a check box next to each message and then press delete which will delete the selected.

<input name="delete" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />

This is my code:

[PHP]
$delete = $_POST['delete'];

foreach ($delete as $deleted) {
$sql = mysql_query("DELETE * FROM messages WHERE id='$deleted'");

}
[/PHP]

This is not working though. Any ideas?

Cheers,
Adam
Feb 13 '08 #1
Share this Question
Share on Google+
6 Replies


P: 11
Hi,

I have a system in place like an inbox which people can select a check box next to each message and then press delete which will delete the selected.

<input name="delete" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />

This is my code:

[PHP]
$delete = $_POST['delete'];

foreach ($delete as $deleted) {
$sql = mysql_query("DELETE * FROM messages WHERE id='$deleted'");

}
[/PHP]

This is not working though. Any ideas?

Cheers,
Adam
Hi there,
Try replacing 'delete' with 'delete[]' as the name to post checkbox values as an array, eg:

Expand|Select|Wrap|Line Numbers
  1. <input name="delete[]" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />
  2.  
Feb 13 '08 #2

100+
P: 133
I have just tried this and it appears that it does not work :( Any ideas?
Feb 13 '08 #3

Markus
Expert 5K+
P: 6,050
echo the deleted out, to see if its being passed.
[php]
$delete = $_POST['delete'];

foreach ($delete as $deleted)
{
echo $deleted . "<br />";
// $sql = mysql_query("DELETE * FROM messages WHERE id='$deleted'");
}
[/php]
Feb 13 '08 #4

100+
P: 133
No nothing is being passed :S

Why do you think that is?
Feb 13 '08 #5

Markus
Expert 5K+
P: 6,050
Post the code for your form please :)

We'll have a harder look!
Feb 13 '08 #6

100+
P: 133
Ok great, i am using smarty so if the tags look weird thats why.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form action="send-message-process.php?type=delete" method="post" name="frm1" id="frm1">
  3.  
  4.              <input type="submit" name="Submit3" value="Delete" class="buttons" />
  5.  
  6.         <table width="100%" border="0" cellspacing="0" cellpadding="3">
  7.                                 <tr>
  8.                                   <td width="4%" height="30" background="images/red-nav-bar.jpg"><h2 class="white">
  9.                                       <input name="allbox2" type="checkbox" id="allbox2" value="checkbox" onclick='checkedAll(frm1);'/>
  10.                                   </h2></td>
  11.                                   <td colspan="2" background="images/red-nav-bar.jpg"><h2><span class="white">Sender</span></h2>                                    </td>
  12.                                   <td width="61%" background="images/red-nav-bar.jpg"><h2><span class="white">Subject</span></h2></td>
  13.                                   <td width="15%" background="images/red-nav-bar.jpg"><h2 class="white">Date</h2></td>
  14.                                 </tr>
  15.                                 {php} 
  16.                                 $sqls = mysql_query("SELECT * FROM messages WHERE profileid = '$_COOKIE[id]'"); 
  17.                                 while($rows = mysql_fetch_array($sqls)){ 
  18.                                 {/php}
  19.                                 <tr>
  20.                                         <td bgcolor="#FCE4E5"><input name="delete[]" type="checkbox" id="delete[]" value="{php} print $rows['id']; {/php}" /></td>
  21.                                   <td width="10%" bgcolor="#FCE4E5"> {php} 
  22.                                     $sql = mysql_query("SELECT * FROM users WHERE id = '$rows[userid]'"); 
  23.                                     while($row = mysql_fetch_array($sql)){ 
  24.                                     {/php} <a href="message-details.php?id={php} print $row['id']; {/php}"><img src="profile/thumbs/{php} print $row['image_1']; {/php}" width="50" height="40" border="0" /></a> {php} } {/php} <br />                                        </td>
  25.                                   <td width="10%" bgcolor="#FCE4E5"><a href="message-details.php?id={php} print $row['id']; {/php}">{php} print $rows[username]; {/php}</a></td>
  26.                                   <td bgcolor="#FCE4E5"><a href="message-details.php?id={php} print $rows[id]; {/php}">{php} print $rows[title]; {/php}</a></td>
  27.                                   <td bgcolor="#FCE4E5">{php} print $rows['sdate']; {/php}</td>
  28.                                 </tr>
  29.                                 {php} } {/php}
  30.                               </table>
  31.                               <p><a href="#" onclick='checkedAll(frm1);'>Select All</a> / <a href="#" onclick='checkedAll(frm1);'>Unselect All</a> </p>
  32.  
  33.        <input type="submit" name="Submit22" value="Delete" class="buttons" />
  34.  
  35.                               </p>
  36.                             </form>
  37.  
  38.  
Feb 13 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.