473,325 Members | 2,774 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,325 software developers and data experts.

Delete With CheckBox POST

25
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_array($rs))
{
$currentCom_id = $row["com_id"];
?>
<TR style="COLOR: #333333; BACKGROUND-COLOR: #d7d6d3">
<TD><A style="COLOR: #333333"
href="adminlogin.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 3968
iam_clint
1,208 Expert 1GB
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 Expert 1GB
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_delete[]" 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("DELETE 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
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...
17
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...
4
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...
9
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...
4
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... ...
1
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...
15
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...
13
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.. ...
1
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)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.