473,769 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ 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_d elete[$php_delete_cou nter]'>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_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
$php_delete_cou nter = 0;
while ($php_row = mysql_fetch_obj ect($php_result ID))
{
if ($frm_chk_delet e[$php_delete_cou nter] == 'on')
{
$php_SQL = "DELETE FROM basics WHERE member_name =
'".$php_mem_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
}
$php_delete_cou nter++;
}

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 8127
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_d elete[$php_delete_cou nter]" value="1">

and detect like so...

if ($frm_chk_delet e[$php_delete_cou nter] == 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_cou nter ?>

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_d elete[$php_counter]"
VALUE="1">Delet e

Then in my called post php script:

$php_SQL = "SELECT * FROM names WHERE member_name =
'".$php_mem_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
$php_delete_cou nter = 0;
while ($php_row = mysql_fetch_obj ect($php_result ID))
{
if ($frm_chk_delet e[$php_delete_cou nter] == 1)
{

}
$php_delete_cou nter++;
}
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_cou nter]" value="1">

and detect like so...

if ($frm_chk_delet e[$php_delete_cou nter] == 1)


Jul 17 '05 #3
Ralph Freshour <ra***@primemai l.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_d elete[$php_counter]"
VALUE="1">Delet e


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_d elete[$php_counter]" .... if ($frm_chk_delet e[$php_delete_cou nter] == 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("SE LECT * FROM basics");
while($row = mysql_fetch_row ) {
$id = $row[0];
echo <<<CHECKBOX
<input type="checkbox" name="frm_chk_d elete[]" 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("DE LETE FROM basics WHERE basics_id IN ($list_of_ids)" );

$php_SQL = "SELECT * FROM basics WHERE member_name =
'".$php_mem_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
$php_delete_cou nter = 0;
while ($php_row = mysql_fetch_obj ect($php_result ID))

Ralph Freshour <ra***@primemai l.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_d elete[$php_delete_cou nter]'>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_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
$php_delete_cou nter = 0;
while ($php_row = mysql_fetch_obj ect($php_result ID))
{
if ($frm_chk_delet e[$php_delete_cou nter] == 'on')
{
$php_SQL = "DELETE FROM basics WHERE member_name =
'".$php_mem_nam e."'";
$php_resultID = mysql_query($ph p_SQL, $php_linkID);
}
$php_delete_cou nter++;
}

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
13224
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: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
1
8750
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware tblSoftware ------------------- ------------------ ---------------------- PID PName PID* SID* SID SWName --- ----- --- --- --- ------ 1 Thomas 1 1 ...
2
8339
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 checkboxes like this: chk1 chk1 chk1 But I need to name them with an array for deletion purposes which is already coded and working - I need to name them like this:
8
2842
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 is my code line that creates each checkbox (the php variable get
6
14759
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' name='cbtype' value='3'> I'm wanting to re-display the same checkboxes, but if the user previously checked one of them then I want it automatically checked on
1
2953
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 Primary Key - ComputerID (AutoNumber) ComputerName
4
2579
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 having a huge list of names , so i want to keep a function so that i can go to (scroll) the name which starts with a particular alphabet & i can check it for selecting components to form a group. both are in different frames. Thanks in...
3
16222
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 can i automate this process? I started with the simple macro builder and entered all 6 queries perfectly fine. However, i want to prompt the user if they wish to run queries 1 & 2, if they say no, it should move to 3 and run the remaining ones....
5
7040
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 comfortably getting entered into the database but the real problem is with the checkboxes..only one entry is being stored ...but i want to enter the multiple entries from the checkboxes to enter into the database...the form is a voting poll..and i...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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
10206
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
10035
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...
1
9984
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
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...
1
7403
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
5293
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3949
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

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.