Connecting Tech Pros Worldwide Help | Site Map

Checkbox array

  #1  
Old March 6th, 2006, 10:55 AM
Paul Morrison
Guest
 
Posts: n/a
Hi,

I have a checkbox array containing the id of a record in a MySQL database.
The checkboxes are created dynamically depending on what is stored in the
database. I want to send the checkbox array to my stop_subscriptions.php
file, running the code on all checked boxes, however I dont seem to be able
to actually send the array, I was hoping that someone could steer me in the
right direction.

Cheers,

Paul

<?php
$sql = "SELECT i.type, i.title , s.inj_id FROM inj_subscription s,
injustices i WHERE s.member_id = '$user' AND i.inj_id = s.inj_id AND
s.inj_id IS NOT null" ;
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result) ;
if ($row) {
echo "<div><span>Specific Subsriptions:</span><br/>" ;
$table_start ='<table width="90%" table name="table2" align="center"
cellspacing="0" border="0">
<tr>
<form method="post" action="stop_subscription.php">
<th width="20%">Type</th>
<th width="70%">Title</th>
<th width="10%"></th>
<input type="submit" name="Submit" value="Submit"
style="font-size:10px"/><p>
<input type="hidden" name="stop_subscription"
value="1"/>
</form>
</tr>';
echo $table_start;
$rownum = 0;
while($row) {
$rownum++;
$style = rowcolor($rownum);
$table_rows .= '<td id="td" align="center"
style="'.$style.';padding:5px;" >'."\n".'<form><input type="checkbox"
name="deletethis[]" value="'.$row['inj_id'] . '"></form></td>'."\n\t";
echo "<tr>" . $table_rows . "</tr>";
$row = mysql_fetch_assoc($result) ;
}
echo '</table><Br/></div><br/>';
}
?>


  #2  
Old March 6th, 2006, 11:15 AM
Kimmo Laine
Guest
 
Posts: n/a

re: Checkbox array


"Paul Morrison" <nospam@nospam.com> wrote in message
news:duh3rd$lt2$1@oheron.kent.ac.uk...[color=blue]
> Hi,
>
> I have a checkbox array containing the id of a record in a MySQL database.
> The checkboxes are created dynamically depending on what is stored in the
> database. I want to send the checkbox array to my stop_subscriptions.php
> file, running the code on all checked boxes, however I dont seem to be
> able to actually send the array, I was hoping that someone could steer me
> in the right direction.
>[/color]

The problem is not that you are submitting an array, the problem is with the
form tags. See comments below.
[color=blue]
>
> <?php
> $sql = "SELECT i.type, i.title , s.inj_id FROM inj_subscription s,
> injustices i WHERE s.member_id = '$user' AND i.inj_id = s.inj_id AND
> s.inj_id IS NOT null" ;
> $result = mysql_query($sql);
> $row = mysql_fetch_assoc($result) ;
> if ($row) {
> echo "<div><span>Specific Subsriptions:</span><br/>" ;
> $table_start ='<table width="90%" table name="table2"
> align="center" cellspacing="0" border="0">
> <tr>
> <form method="post" action="stop_subscription.php">
> <th width="20%">Type</th>
> <th width="70%">Title</th>
> <th width="10%"></th>
> <input type="submit" name="Submit" value="Submit"
> style="font-size:10px"/><p>
> <input type="hidden" name="stop_subscription"
> value="1"/>
> </form>[/color]

The form ends here in the </form> tag
[color=blue]
> </tr>';
> echo $table_start;
> $rownum = 0;
> while($row) {
> $rownum++;
> $style = rowcolor($rownum);
> $table_rows .= '<td id="td" align="center"[/color]

then you begin another form here, apparently each checkbox gets their own
form since it's inside the while loop.
[color=blue]
> style="'.$style.';padding:5px;" >'."\n".'<form><input type="checkbox"
> name="deletethis[]" value="'.$row['inj_id'] . '"></form></td>'."\n\t";
> echo "<tr>" . $table_rows . "</tr>";
> $row = mysql_fetch_assoc($result) ;
> }
> echo '</table><Br/></div><br/>';
> }
> ?>[/color]


All fields that you want to post must be within the SAME <form>...</form>
range, any fields outside that range, or fields inside another form are not
posted when a form is submitted. Change the code so that you generate just
one form, and all your form fields are inside that same form.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


  #3  
Old March 6th, 2006, 11:25 AM
Paul Morrison
Guest
 
Posts: n/a

re: Checkbox array


> All fields that you want to post must be within the SAME <form>...</form>[color=blue]
> range, any fields outside that range, or fields inside another form are
> not posted when a form is submitted. Change the code so that you generate
> just one form, and all your form fields are inside that same form.[/color]

How can I enclose all parts of the form? When I first create the table I
need to open the form tag, but in order to enclose the checkboxes as well it
therefore needs to close after all the checkboxes have been created. I have
tried starting the form before I create the table and it doesn't like it.

Paul


  #4  
Old March 6th, 2006, 12:05 PM
Erwin Moller
Guest
 
Posts: n/a

re: Checkbox array


Paul Morrison wrote:
[color=blue][color=green]
>> All fields that you want to post must be within the SAME <form>...</form>
>> range, any fields outside that range, or fields inside another form are
>> not posted when a form is submitted. Change the code so that you generate
>> just one form, and all your form fields are inside that same form.[/color]
>
> How can I enclose all parts of the form? When I first create the table I
> need to open the form tag, but in order to enclose the checkboxes as well
> it therefore needs to close after all the checkboxes have been created. I
> have tried starting the form before I create the table and it doesn't like
> it.
>
> Paul[/color]

Kimmo said that you closed the form too early.
So put the </form> after all form-elements, including all checkboxes and
submitbutton.

So solution is simple: move the </form> after the loop and the submitbutton.

Regards,
Erwin Moller
  #5  
Old March 6th, 2006, 12:25 PM
Kimmo Laine
Guest
 
Posts: n/a

re: Checkbox array


"Paul Morrison" <nospam@nospam.com> wrote in message
news:duh57p$n85$1@oheron.kent.ac.uk...[color=blue][color=green]
>> All fields that you want to post must be within the SAME <form>...</form>
>> range, any fields outside that range, or fields inside another form are
>> not posted when a form is submitted. Change the code so that you generate
>> just one form, and all your form fields are inside that same form.[/color]
>
> How can I enclose all parts of the form? When I first create the table I
> need to open the form tag, but in order to enclose the checkboxes as well
> it therefore needs to close after all the checkboxes have been created. I
> have tried starting the form before I create the table and it doesn't like
> it.[/color]


Doesn't like it? What the hell does that mean? Just do it like this:

<form method="post" action="stop_subscription.php">

then all your php code here, the table, checkboxes, submit buttons,
everything, the whole shebang here and finally after all that close the
form:

</form>

My code always likes it like that.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
send checkbox array in javascript function realin answers 3 April 29th, 2008 04:31 PM
vb-Checkbox Array? Sample Code needed Nolanclark answers 0 September 11th, 2007 09:15 PM
Checkbox array passes to script fine but doesn't mail right JackM answers 3 February 1st, 2007 01:35 AM
Checkbox Array WC Justice answers 4 July 19th, 2005 02:33 PM