Home > Archive > PHP SQL > June 2006 > checkbox handling
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Harold 2006-06-19, 7:06 pm |
|
keep in mind in am new to PHP.
here is a snippet of some of the checkbox options...
<tr>
<td><input type=checkbox name=skill04/>Ad Design</td>
<td><input type=checkbox name=skill05/>Animation</td>
<td><input type=checkbox name=skill06/>ASP</td>
</tr>
what i want to do is pass a userid( lets call that userid) along with
any of the items that are checked only.
userid is from a text box entry
so if ad design and ASP are only selected i want both of them in the table
user id | skill
----------------
123 | Ad design
123 | ASP
any help appreciated.
Thanks
| |
| Martie 2006-06-24, 8:06 am |
| On Mon, 19 Jun 2006 20:03:36 +0000 (UTC), Harold wrote...
>
>
>keep in mind in am new to PHP.
>
>here is a snippet of some of the checkbox options...
>
><tr>
><td><input type=checkbox name=skill04/>Ad Design</td>
><td><input type=checkbox name=skill05/>Animation</td>
><td><input type=checkbox name=skill06/>ASP</td>
></tr>
>what i want to do is pass a userid( lets call that userid) along with
>any of the items that are checked only.
>
>
>
>
>userid is from a text box entry
>
>so if ad design and ASP are only selected i want both of them in the table
>
>user id | skill
>----------------
>123 | Ad design
>123 | ASP
>
>
>any help appreciated.
>
>Thanks
>
>
When using checkboxes, I believe only the checked selections are sent when the
form is being submitted. May want to consider adding something like "value=true"
to each of the checkboxes. That way when you can check the value before
inserting it into the table.
<?php
if($_POST['skill04'] == "true")
{
$selected_array[] = "skill04";
}
if($_POST['skill05'] == "true")
{
$selected_array[] = "skill05";
}
if($_POST['skill06'] == "true")
{
$selected_array[] = "skill06";
}
?>
That would give you and scalar/indexed array of only the selected items from
your form.
Martie
--
Unlimited Newsgroup Downloads / $19.95 month
More Details - http://newsguy.com/overview.htm
| |
| no@emails.thx 2006-06-24, 8:06 am |
| On Mon, 19 Jun 2006 20:03:36 +0000 (UTC), Harold <harhem@cogeco.ca>
wrote:
>keep in mind in am new to PHP.
>here is a snippet of some of the checkbox options...
>
><tr>
><td><input type=checkbox name=skill04/>Ad Design</td>
><td><input type=checkbox name=skill05/>Animation</td>
><td><input type=checkbox name=skill06/>ASP</td>
></tr>
>what i want to do is pass a userid( lets call that userid) along with
>any of the items that are checked only.
>
>userid is from a text box entry
>
>so if ad design and ASP are only selected i want both of them in the table
>
>user id | skill
>----------------
>123 | Ad design
>123 | ASP
The previous poster is correct in saying that checkboxes are only
passed to the receiving form if they have been ticked. So, the trick
would be to set value="'.$userid.'" in the checkbox.
Or even (untested) do this:
<input type="hidden" name="userid" value="'.$userid.'" />
<tr>
<td><input type=checkbox name="skillset[]" value="Ad Design" />Ad
Design</td>
<td><input type=checkbox name="skillset[]" value="Animation"
/>Animation</td>
<td><input type=checkbox name="skillset[]" value="ASP" />ASP</td>
</tr>
.... perhaps :-)
Then in the receiving page:
foreach ( $_post['skillset'] in $key => $value ) {
'INSERT INTO table VALUES
("","'.mysql_escape_string($_post['userid']).'","'.mysql_escape_string($value]).'")'
}
(obviously put the INSERT into a suitable command. I am assuming the
first field will be an autoincrementing id.)
Apologies if there is some error there - but it's before breakfast so
my brain isn't fully awake! ;-)
Chris R.
|
|
|
|
|