473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Delete Usings Checkboxes

133 100+
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
6 1679
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
adamjblakey
133 100+
I have just tried this and it appears that it does not work :( Any ideas?
Feb 13 '08 #3
Markus
6,050 Expert 4TB
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
adamjblakey
133 100+
No nothing is being passed :S

Why do you think that is?
Feb 13 '08 #5
Markus
6,050 Expert 4TB
Post the code for your form please :)

We'll have a harder look!
Feb 13 '08 #6
adamjblakey
133 100+
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

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

Similar topics

1
by: J | last post by:
Hi, Can someone please help with a problem I have. The BOL I think are useless in explaining what I want to do. I have a datagrid, that is bound to a dataview. I have a checkbox as a...
1
by: clickncook | last post by:
I'm currently working on a website for recipes that allows users to search by ingredients they have and I'm experiencing a problem with my filtering. My site allows users to just check the...
1
by: recordlovelife | last post by:
Hey guys, ill try to make this simple. I want to make a GUI for a client so that they can delete news entries that they have posted. I figure I can code a site that will query the table for the news...
3
by: macxrbest | last post by:
I have checkboxes in a simple spreadsheet being used to check when a cable is terminated. I'm not using any code with the checkboxes. When I added the checkboxes to the spreadsheet, two extra have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.