473,413 Members | 1,794 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,413 software developers and data experts.

Deleting multiple Rows Using Checkbox

25
Hi ,
I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working. My php code is listed as below

[PHP]
<?php
$sql = "Select * from list;";
$result=mysql_query($sql) or die ("<br> Could not Retrieve Data <br>");
$num_rows=mysql_num_rows($result);

While ($row =mysql_fetch_array($rs))
{
$currentCom_id = $row["com_id"];
?>

<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['com_id']; ?>">
.....
.....
<?php

}
?>

<input name="delete" type="submit" id="delete" value="Delete">
[/PHP]

Now for deleting the selected checkbox i have used following SQL queries.

[PHP]

if($_POST['delete'] == "Delete"){
for($j=0;$j<$num_rows;$j++){
$del_id = $checkbox[$j];
$sql = "DELETE FROM committee WHERE com_id='$del_id'";
$result = mysql_query($sql);
echo $result;
}
}
mysql_close();
?>

[/PHP]

The problem is when i press delete it does not deletes the rows selected, else it just reloads the page. I dont know where i am wrong.

can u guyz please help me on this ...
THanks
Apr 8 '07 #1
4 11462
code green
1,726 Expert 1GB
Looks like you are expecting the GLOBAL post vars to be switched on. It is switched off by default in later versions of php. You should not use this anyway. You need to read the checkbox values through the $_POST array
Apr 10 '07 #2
Hi,

i'm gaing the same problem... I change my code to that:

<?
// Check if delete button active, start this
if($_POST['delete'] == 'Delete'){
for($i=0;$i<$count;$i++){
$del_id = $_POST['checkbox'][$i];
$sql = "DELETE FROM $tbl_name WHERE userid='$del_id'";
$result = mysql_query($sql);
}


// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
}
mysql_close();
?>


But it still doesn't work...

Please help.
thx.
Jun 11 '07 #3
epots9
1,351 Expert 1GB
what errors are u getting?
Jun 11 '07 #4
Hi, If any one didn't got the solution yet of this problem and still seeking! Please mail me on DELETED
Feb 13 '08 #5

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

Similar topics

2
by: cool_dude7244 | last post by:
I am retrieving records for Customer ID as follows and displaying them as table rows with a checkbox for multiple deletion. Part of a </FORM>...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
0
by: Patrick.O.Ige | last post by:
I have a datagrid with checkboxes.. When a user clicks one check box and clicks the delete button it deletes that ROw. There another situation when a user clicks multiple rows so i had to loop...
4
by: MasterChief | last post by:
I have a customer that likes the gridview but instead of using the standard Delete command for each row he wants to be able to put a checkbox next to the row so he can chose multiple records and...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
11
by: giloosh | last post by:
i would like to filter out a bunch rows from a table of sql row results. i have a checkbox on each row named checkbox (x = the current row id) i will submit the form and take all the rows that...
10
by: beam1985 | last post by:
So my problem lays in the $_POST if statement at the bottom operation, I keep getting Notice: Undefined index: delete and also Notice: Undefined index: checkbox. Please let me know if you have any...
2
by: Brad Pears | last post by:
I am working on a new vb.net 2005 project using SQL server 2000 as the backend db. I have a listview where control I want a user to be able to select either just one or multiple rows in the...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.