Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009

    PHP: Playing with CheckBox ?


    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


    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 ?

  2. #2
    Join Date
    Jan 2008
    Jax, FL
    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
    Windows VPS // Dedicated Servers // Backup Services
    Wholly owned hardware and self operated network (AS19531) in Jacksonville, FL

  3. #3
    Join Date
    May 2009
    Um...actually, you can go either way (or both) *"your mom" joke here*:

    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

Similar Threads

  1. JS set checkbox by select value?
    By tjphippen in forum Programming Discussion
    Replies: 5
    Last Post: 05-24-2009, 07:21 PM
  2. Checkbox mySQL variable?
    By FG-alex in forum Programming Discussion
    Replies: 3
    Last Post: 10-22-2007, 11:35 AM
  3. Custom Checkbox Script - Need help!
    By Conica in forum Programming Discussion
    Replies: 2
    Last Post: 09-12-2007, 01:50 PM
  4. Checkbox Validation
    By samnite in forum Programming Discussion
    Replies: 3
    Last Post: 07-07-2005, 08:36 PM
  5. Help! Php Checkbox Question
    By spinyalatis in forum Programming Discussion
    Replies: 9
    Last Post: 04-11-2003, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts