Results 1 to 3 of 3
Thread: PHP: Playing with CheckBox ?
-
09-22-2009, 09:23 AM #1WHT Addict
- Join Date
- May 2009
- Posts
- 150
PHP: Playing with CheckBox ?
Hi
I have 2 checkbox fields
<input type="checkbox" name="music[1]"/>
<input type="checkbox" name="music[2]"/>
So when the user tick on those 2 checkboxes and click submit button
the address bar is
order.php?step=1&music[1]=on&music[2]=on
My question is
How can I get the values [1] and [2] using PHP ?
Means, I just want an array with those values, 1 and 2
Any help ?
-
09-22-2009, 09:46 AM #2Web Hosting Master
- Join Date
- Jan 2008
- Location
- Jax, FL
- Posts
- 2,707
It sounds like you are using GET instead of POST -- by using POST the values would not show up in the address bar but would transfer to the script you specify.
In order.php you would access the posted variables by using $_POST[music[1]]
Just be sure to sanitize the values of the posted data if you are going to be doing anything with it and a database -- mysql_real_escape_string() -- never trust user input█ Daniel | Server Complete, LLC
█ INSTANTLY DEPLOYED Bare Metal Servers
█ Wholly owned hardware and self operated network (AS19531) in Jacksonville, FL
-
09-22-2009, 01:21 PM #3Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
Um...actually, you can go either way (or both) *"your mom" joke here*:
http://us2.php.net/manual/en/reserved.variables.get.php
http://us2.php.net/manual/en/reserve...ables.post.php
http://us2.php.net/manual/en/reserve...es.request.php
I'm more curious about the chosen form field names from the original poster. The array syntax is usually reserved for checkbox groups, ie:
PHP Code:<input type="checkbox" name="music[]" value="1">
<input type="checkbox" name="music[]" value="2">
// and then check with
print_r($_REQUEST['music']);
Similar Threads
-
JS set checkbox by select value?
By tjphippen in forum Programming DiscussionReplies: 5Last Post: 05-24-2009, 07:21 PM -
Checkbox mySQL variable?
By FG-alex in forum Programming DiscussionReplies: 3Last Post: 10-22-2007, 11:35 AM -
Custom Checkbox Script - Need help!
By Conica in forum Programming DiscussionReplies: 2Last Post: 09-12-2007, 01:50 PM -
Checkbox Validation
By samnite in forum Programming DiscussionReplies: 3Last Post: 07-07-2005, 08:36 PM -
Help! Php Checkbox Question
By spinyalatis in forum Programming DiscussionReplies: 9Last Post: 04-11-2003, 04:42 AM