473,804 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete With CheckBox POST

25 New Member
Hi,
I am having some problem trying to think how to write a code for deleting the entry which is loaded from the database. I have a while loop which pulls the userID, name etc from the database and i have a checkbox next to each useriD. I also have a Delete button. SO what i want is when delete is clicked it will delete all items which are checked.
My code

[PHP]
<?php $a=0;
$i=0;
While ($row =mysql_fetch_ar ray($rs))
{
$currentCom_id = $row["com_id"];
?>
<TR style="COLOR: #333333; BACKGROUND-COLOR: #d7d6d3">
<TD><A style="COLOR: #333333"
href="adminlogi n.php?mode=comm _del">Edit</A></TD>
<td><input type="checkbox" name="checkbox_ <?php echo $i; ?>" value= <?php echo $currentCom_id ;?>>
</td>
<TD><?php echo $a=$a+1 ; ?> </TD>
<TD><?php echo $row["com_name"] ;?></TD>
<TD><?php echo $row["com_note"] ;?></TD>
<input type="hidden" name= comId_<?php echo $i; ?> value="<?= "$currentCom_id " ?>">

</TR></TBODY>
<?php
$i=$i+1;
}

[/PHP]

So the above code runs fine. SO i am having some problem on how to know which checkbox user checked. SHould i use foreach loop or other way.
PLease help me on this.
Thanks
Mar 28 '07 #1
2 3990
iam_clint
1,208 Recognized Expert Top Contributor
name all of the checkboxes the same then submit the form and in your php get the name of the checkboxes and loop through to see which ones are checked.
Mar 28 '07 #2
ak1dnar
1,584 Recognized Expert Top Contributor
Put your while loop inside a form.then create a array of check boxes.
and always pass the userid in value attribute.

[PHP]<input type="checkbox" name="frm_chk_d elete[]" value="'.$id.'" />[/PHP]

then from the action page.fetch the array.

[PHP]$frm_chk_delete = $_REQUEST['frm_chk_delete '];[/PHP]

the implode the array.

[PHP]$list_of_ids = implode(",", $frm_chk_delete );[/PHP]

use this kind of query to delete your user ids.
[PHP]mysql_query("DE LETE FROM cart WHERE p_id IN ($list_of_ids)" );[/PHP]
Mar 29 '07 #3

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

Similar topics

2
10122
by: neoconwannabe | last post by:
Hi, I have an html form with a number of checkboxes that can be checked to delete items. I want to have a javascript alert prompt box to pop up to confirm the delete. I am building my site with javascript as an enhancement and not a requirement to work. My question is can I have the html form function normally if the user has javascript
17
3469
by: Lag | last post by:
Was wondering if anyone could help me with a PHP, MySQL problem. I am completely new to PHP and MySQL. I have been trying to find a way to list data from a table on a web page and after each individual item have a hyperlink to allow users to delete the information listed. Can anyone help? i.e. Name Age Sex ------------------------------------------ Adam 21 M delete
4
2168
by: MasterChief | last post by:
I am trying to learn how to delete multple items in a database using the code behind file. I would just like somebody to tell me what is wrong with my code. I am new to connecting to the database through a code-behind. I have a gridview called gridview1. When the user checks a bunch of plans then should be able to hit delete and for each checked box it should delete the plan and update the gridview1. Imports System.Data Imports...
9
2801
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like this: id Name Surname pictr0 picrt1 pictr2 pictr3
4
2215
imarkdesigns
by: imarkdesigns | last post by:
Hello everyone.. a newbie programmer here wants to ask why is my codes for deleting rows from my databse won't work.... seems that this codes spread to the net and no one refuse to correct it... can someone correct this... <!-- Editable Area --> <?php include ("../dbconnection/connect.php"); $tbl_name="schedule"; // Table name
1
2836
by: chocciies | last post by:
Hi! I want to delete multiple record via checkboxes. However, with no success. Is there sthg wrong with the value of my checkbox? Your help will be greatly appreciated. Thanks! <form name="form1" method="post" action=""> <p> <?php
15
3779
by: Morteneistrom | last post by:
Im a complete n00b at PHP so please forgive me if this i a stupid question Why wont the following work. PHP Code: <?php foreach (glob('../images/profil/*.jpg') as $filename) { echo "$filename <br>". "<a href="unlink('$filename');">Delete</ a>";
13
26939
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. Regards Ramprakash /*Adminpage.jsp*/ <%@ page language="java" import="java.sql.*"%> <html> <head>...
1
4165
by: ahilar12 | last post by:
Hi all, I am new to php,my question is that in this following code i am retrieving many rows from the database which is working good.i want to delete a particular row(s) which is checked(checkbox) and this should be done when the deletecontact button is clicked and also should be deleted int the database also Somebody help me out on this code <html> <head> <script type="text/javascript"> function SetAllCheckBoxes(FormName,...
0
9587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
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
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10085
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
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
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
3
2998
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.