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

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 8095
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
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
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
2
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.