473,487 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple Checkboxes Help Needed

I'm using MySQL to display data on a web page - fitting about 10
records of data per screen - I'm including a checkbox with each record
so that I can check it and when the submit button is clicked the
called .php script will delete those records that are checked.

I'm creating the records from the table with the checkboxes ok (I
think):

<INPUT TYPE='checkbox'
NAME='frm_chk_delete[$php_delete_counter]'>Delete

I use a php counter var to give each checkbox record item a unique
NAME and this seems to work OK - producing
frm_chk_delete[0]
frm_chk_delete[1]
etc.

The problem I'm having is the POST called script - I don't seem to be
detecting enabled checkboxes to delete them:

$php_mem_name = Trim(StrToLower($php_name));
$php_SQL = "SELECT * FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_delete_counter = 0;
while ($php_row = mysql_fetch_object($php_resultID))
{
if ($frm_chk_delete[$php_delete_counter] == 'on')
{
$php_SQL = "DELETE FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
}
$php_delete_counter++;
}

Can anyone see what I'm doing wrong or that I'm not understanding
about how to do this task?

Thanks...

Jul 17 '05 #1
5 8102
I noticed that Message-ID: <34********************************@4ax.com>
from Ralph Freshour contained the following:
Can anyone see what I'm doing wrong or that I'm not understanding
about how to do this task?


You have to give the checkbox a value to return if checked. e.g
<INPUT TYPE='checkbox'
NAME="frm_chk_delete[$php_delete_counter]" value="1">

and detect like so...

if ($frm_chk_delete[$php_delete_counter] == 1)

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
I tried that but it only detects the first checkbox - if I have 5
records displayed and I check all 5 and then click on submit, only the
first checkbox is detected as checked, the others do not get detected.

I also tried:

VALUE=<?php echo $php_delete_counter ?>

in the checkbox so each would get a unique value but that didn't seem
to matter either - maybe my syntax is wrong somewhere?:

<INPUT TYPE="checkbox" NAME="frm_chk_delete[$php_counter]"
VALUE="1">Delete

Then in my called post php script:

$php_SQL = "SELECT * FROM names WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_delete_counter = 0;
while ($php_row = mysql_fetch_object($php_resultID))
{
if ($frm_chk_delete[$php_delete_counter] == 1)
{

}
$php_delete_counter++;
}
On Thu, 18 Sep 2003 07:24:16 +0100, Geoff Berrow <$b**@ckdog.co.uk>
wrote:
I noticed that Message-ID: <34********************************@4ax.com>
from Ralph Freshour contained the following:
Can anyone see what I'm doing wrong or that I'm not understanding
about how to do this task?


You have to give the checkbox a value to return if checked. e.g
<INPUT TYPE='checkbox'
NAME="frm_chk_delete[$php_delete_counter]" value="1">

and detect like so...

if ($frm_chk_delete[$php_delete_counter] == 1)


Jul 17 '05 #3
Ralph Freshour <ra***@primemail.com> wrote:
I tried that but it only detects the first checkbox - if I have 5
records displayed and I check all 5 and then click on submit, only the
first checkbox is detected as checked, the others do not get detected.

<INPUT TYPE="checkbox" NAME="frm_chk_delete[$php_counter]"
VALUE="1">Delete


Hi Ralph,

How do you build up the list of checkboxes? Are you sure $php_counter is
incremented for each checkbox name?

JOn
Jul 17 '05 #4
I noticed that Message-ID: <ei********************************@4ax.com>
from Ralph Freshour contained the following:
<INPUT TYPE="checkbox" NAME="frm_chk_delete[$php_counter]" .... if ($frm_chk_delete[$php_delete_counter] == 1)


Could this be your problem?

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5
A simpler (as well as quicker) way to do this would be to use the id
of the record as the value in the checkbox. Thus:

$res_id = mysql_query("SELECT * FROM basics");
while($row = mysql_fetch_row) {
$id = $row[0];
echo <<<CHECKBOX
<input type="checkbox" name="frm_chk_delete[]" value="$id"> ...
CHECKBOX;
}

When the form is submit, the ids those records that are selected will
be in frm_chk_delete. All you have to do to delete them is to run a
DELETE using the IN keyword.

$list_of_ids = implode(",", $frm_chk_delete);
mysql_query("DELETE FROM basics WHERE basics_id IN ($list_of_ids)");

$php_SQL = "SELECT * FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_delete_counter = 0;
while ($php_row = mysql_fetch_object($php_resultID))

Ralph Freshour <ra***@primemail.com> wrote in message news:<34********************************@4ax.com>. .. I'm using MySQL to display data on a web page - fitting about 10
records of data per screen - I'm including a checkbox with each record
so that I can check it and when the submit button is clicked the
called .php script will delete those records that are checked.

I'm creating the records from the table with the checkboxes ok (I
think):

<INPUT TYPE='checkbox'
NAME='frm_chk_delete[$php_delete_counter]'>Delete

I use a php counter var to give each checkbox record item a unique
NAME and this seems to work OK - producing
frm_chk_delete[0]
frm_chk_delete[1]
etc.

The problem I'm having is the POST called script - I don't seem to be
detecting enabled checkboxes to delete them:

$php_mem_name = Trim(StrToLower($php_name));
$php_SQL = "SELECT * FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
$php_delete_counter = 0;
while ($php_row = mysql_fetch_object($php_resultID))
{
if ($frm_chk_delete[$php_delete_counter] == 'on')
{
$php_SQL = "DELETE FROM basics WHERE member_name =
'".$php_mem_name."'";
$php_resultID = mysql_query($php_SQL, $php_linkID);
}
$php_delete_counter++;
}

Can anyone see what I'm doing wrong or that I'm not understanding
about how to do this task?

Thanks...

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13203
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
1
8727
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
2
8325
by: Ralph Freshour | last post by:
I have a function that I call to check or uncheck all checkboxes on a form - I use a 'master' checkbox to do this much like hotmail has to check all mail messages - the code works fine if I name my...
8
2808
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
6
14745
by: jeffsnox | last post by:
Hi, I have multiple checkboxes on the same form as follows: <input type='checkbox' name='cbtype' value='1'> <input type='checkbox' name='cbtype' value='2'> <input type='checkbox'...
1
2916
by: projectjakecs | last post by:
Hi, I am working on a ms access database and I am having trouble using a form to create new records in an associative table. Here is the breakdown of my database: Main Table - Computer...
4
2533
by: ramapv | last post by:
can i highlight a checkbox from a group of checkbox with particular name which is given as a search key. I am having a list of checkboxes and i have to select some of them and form a group.but i'm...
3
16181
by: swb76 | last post by:
Hi, I have 6 queries in Access that run great. They need to be run in sequence with the first 5 queries writing to tables and the sixth one pops up the final results in datasheet view. Now, how...
5
6951
by: TechnoAtif | last post by:
Hi All..'mAtif..i've got stuck within checkboxes these days..i've got many input items like checkboxes,textarea and along with them there are many checkboxes...all the data except the checkbox's is...
0
7106
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
7137
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,...
1
6846
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
5442
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,...
0
4565
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...
0
3076
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...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
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...

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.