multi select box

Discussion in 'PHP' started by barnes, May 1, 2007.

  1. #1
    hi to all
    i need small help in php.
    how to store multi select box values in database.suppose one person prefers 2 or 3 cities in a country.during the normal process last selected value is stored in database.but i want to store all selected values in multiple select box.
    thanks in advance..
     
    barnes, May 1, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Add these brackets [] to your HTML form. Behind the checkbox name, to be exact.
    
    <input type="checkbox" name="foo[]" />
    
    HTML:
    This will convert the the variable foo into an array, and you can receive all values in your PHP script.

    
    print_r($_POST['foo']);
    
    PHP:
     
    nico_swd, May 1, 2007 IP