473,800 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Usings Checkboxes

133 New Member
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("DE LETE * FROM messages WHERE id='$deleted'") ;

}
[/PHP]

This is not working though. Any ideas?

Cheers,
Adam
Feb 13 '08 #1
6 1697
ajcolburn
11 New Member
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("DE LETE * 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 New Member
I have just tried this and it appears that it does not work :( Any ideas?
Feb 13 '08 #3
Markus
6,050 Recognized Expert Expert
echo the deleted out, to see if its being passed.
[php]
$delete = $_POST['delete'];

foreach ($delete as $deleted)
{
echo $deleted . "<br />";
// $sql = mysql_query("DE LETE * FROM messages WHERE id='$deleted'") ;
}
[/php]
Feb 13 '08 #4
adamjblakey
133 New Member
No nothing is being passed :S

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

We'll have a harder look!
Feb 13 '08 #6
adamjblakey
133 New Member
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
1815
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 template column and a button marked 'delete'. What I want to do, is be able to select a series of rows from the datagrid, using the checkboxes, and delete them from the table when I click the delete
1
2128
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 checkboxes of ingredients they have. I've been in and out of every forum I can find on the internet any solution and this forum has been pretty helpful! I'm using PostNuke for my CMS & the bulk of my program is run through Pagesetter. I can get my simple...
1
2589
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 and post the titles of all of the news entries, and put a check box next to each one. The name of the check box will be the id number of the row in the MySQL table where the news entry is located. So if they click a check box, when they hit submit,...
3
1745
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 showed up in the middle of the page and they can't be deleted. I need some vb code to delete either specific checkboxes or all of them.
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.