checkbox handling

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
Harold [ Mo, 19 Juni 2006 22:03 ] [ ID #1361416 ]

Re: checkbox handling

Post removed (X-No-Archive: yes)
Notifier Deamon [ Di, 20 Juni 2006 19:40 ] [ ID #1362931 ]

Re: checkbox handling

On Mon, 19 Jun 2006 20:03:36 +0000 (UTC), Harold <harhem [at] 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_esc ape_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.
no [ Mi, 21 Juni 2006 09:12 ] [ ID #1364729 ]
PHP » alt.php.sql » checkbox handling

Vorheriges Thema: comparing two mysql tables
Nächstes Thema: making a list to ban Guest Book entries.