Thread: option values

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    26
    Rep Power
    0
    From my experimentation there seems to be a difference when using values from an option value as apposed to an value by a check box etc. I can quite easily input data from a check box selection, but not an option value.

    An option value:
    <select name="horo">
    <option value="none" selected><None> </option>
    <option value="aquarius">Aquarius</option>
    <option value="pisces">Pisces</option>
    <option value="aries">Aries</option>
    <option value="taurus">Taurus</option>
    <option value="gemini">Gemini</option>
    <option value="cancer">Cancer</option>
    <option value="leo">Leo</option>
    <option value="virgo">Virgo</option>
    <option value="libra">Libra</option>
    <option value="scorpio">Scorpio</option>
    <option value="sagittarius">Sagittarius</option>
    <option value="capricorn">Capricorn</option>
    </select>

    **********Check box value:


    <
    input type="checkbox" name="news" value="news">


    I can easily insert the check box data into the table with the following:

    // Inserting user data into headline table..
    $result=mysql_query("INSERT INTO headline (headlines) VALUES ('$news $sport')",$con);


    *************...But for the option value using the same style of:

    // Inserting user data into horoscope table..
    $result=mysql_query("INSERT INTO horoscope (horo) VALUES ('$pisces $aries $taurus $gemini $cancer $leo $virgo $libra $scorpio $sagittarius $capricorn')",$con);


    Does not insert any values into the table.

    Ayone with any experience on this subject would be appreciated.

    Regards

    Richard
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    your select name needs to be horo[] because it will be an array when it gets to your script then you need to manipluate the array somehow before inserting it into the db like creating a string separated by comas out of each element in the array. If you don't do this, you will only get the first value from the list
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <select name="horo">


    You should use "multiple" option inside the select tag for getting multiple values form list box..

    --It should be:

    <select size="5" name="horo[]" multiple>
    ...
    </select>


    -----------


    manipluate the array somehow before inserting it into the db like creating a string separated by comas out of each element in the array.


    ----

    for that you may use ...

    implode() function..

    $values=implode(',',$horo[]);


    then insert that into database..

    $result=mysql_query("INSERT INTO horoscope (horo) VALUES ('$values')",$con);

    just give a try..


    Good Luck!!




    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Replies: 3
    Last Post: January 16th, 2004, 12:26 PM
  2. Zip code validation
    By krwyth in forum MySQL Help
    Replies: 2
    Last Post: January 5th, 2004, 01:29 PM
  3. is it possible to change values in an option list?
    By dlkingace in forum HTML Programming
    Replies: 3
    Last Post: November 17th, 2003, 12:47 AM
  4. combining pulldown option values
    By Spud in forum HTML Programming
    Replies: 3
    Last Post: November 12th, 2003, 03:43 PM
  5. w3c strict errors (10), css, and js questions
    By WorldBuilder in forum CSS Help
    Replies: 12
    Last Post: November 6th, 2003, 04:48 AM

IMN logo majestic logo threadwatch logo seochat tools logo