Connecting Tech Pros Worldwide Forums | Help | Site Map

Multiple Checkboxes Help Needed

Ralph Freshour
Guest
 
Posts: n/a
#1: Jul 17 '05
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...


Geoff Berrow
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Multiple Checkboxes Help Needed


I noticed that Message-ID: <34bimvo9sh69d5im09viomebpmuffmpsgs@4ax.com>
from Ralph Freshour contained the following:
[color=blue]
>Can anyone see what I'm doing wrong or that I'm not understanding
>about how to do this task?[/color]

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/
Ralph Freshour
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Multiple Checkboxes Help Needed


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 <$bl$@ckdog.co.uk>
wrote:
[color=blue]
>I noticed that Message-ID: <34bimvo9sh69d5im09viomebpmuffmpsgs@4ax.com>
>from Ralph Freshour contained the following:
>[color=green]
>>Can anyone see what I'm doing wrong or that I'm not understanding
>>about how to do this task?[/color]
>
>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)[/color]

Jon Kraft
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Multiple Checkboxes Help Needed


Ralph Freshour <ralph@primemail.com> wrote:
[color=blue]
> 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[/color]

Hi Ralph,

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

JOn
Geoff Berrow
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Multiple Checkboxes Help Needed


I noticed that Message-ID: <eiejmv0f5q2t89bct0bk9qm13jf9i3bdgb@4ax.com>
from Ralph Freshour contained the following:
[color=blue]
><INPUT TYPE="checkbox" NAME="frm_chk_delete[$php_counter]"[/color]
....[color=blue]
> if ($frm_chk_delete[$php_delete_counter] == 1)[/color]

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/
Chung Leong
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Multiple Checkboxes Help Needed


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 =[color=blue]
> '".$php_mem_name."'";
> $php_resultID = mysql_query($php_SQL, $php_linkID);
> $php_delete_counter = 0;
> while ($php_row = mysql_fetch_object($php_resultID))
>[/color]

Ralph Freshour <ralph@primemail.com> wrote in message news:<34bimvo9sh69d5im09viomebpmuffmpsgs@4ax.com>. ..[color=blue]
> 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...[/color]
Closed Thread