Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

HTML Lists/Menus - Submitting multiple options with PHP

  • 13-08-2007 12:33pm
    #1
    Closed Accounts Posts: 230 ✭✭


    I've been trying to pull a list of variables between two pages with no luck. I'm just using the basic $_GET["X"]; (where X is the name of the list). When I make multiple selections, it only gives me the last one as output.

    Anyone got any ideas?

    Thanks in advance.


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    The issue with the multiple select is the way that the browser posts or gets the variables.

    For example, if you have a select called "mySelect", and someone has selected three of the values from it, the the query string in the get, will look a little like this:

    mypage.php?mySelect=5&mySelect=7&mySelect=18

    When the variables are passed to PHP, it only sees one value for mySelect - the last one, because the previous two are overwritten.

    You need to rename the variable to include brackets at the end, so mySelect[]. This tells PHP to create an array called "mySelect", and every time a value is added to "mySelect[]", PHP adds it to the end of the array.

    So then you just access it as $_GET[0], etc.


  • Closed Accounts Posts: 230 ✭✭danindublin


    Hi Seamus,

    Thanks for your help, seems to have go me a little down the road but havent got further than the first value.

    //Select Section

    <select name="s1" size="1" multiple="multiple" class="lst2" id="s1">
    <option>Mr Ape</option>
    <option>Mr Bird</option>
    <option>Mr Cat</option>
    <option>Mr Dog</option>
    <option>Mr Elephant</option>
    <option>Mr Fish</option>
    </select>


    //Attempt A - Seems to just add one char at a time until it gets to the end of the first string, then goes blank

    $val .= $_GET[0];
    $val .= $_GET[1];
    $val .= $_GET[2];
    $val .= $_GET[3];
    $val .= $_GET[4];
    $val .= $_GET[5];

    //Attempt B - Only returns the last string

    $val .= "Start A<br/>";
    $val .= $_POST["s1"][0];
    $val .= "<br/>Get value from 0<br/>";
    $val .= $_POST["s1"][1];
    $val .= "<br/>Get value from 1<br/>";
    $val .= "Finished A<br/>";

    :confused::confused::confused:


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    You're still not creating the array :)

    <select name = "s1[]"


  • Closed Accounts Posts: 230 ✭✭danindublin


    seamus wrote:
    You're still not creating the array :)

    <select name = "s1[]"

    :D Seamus you're a genius! Thanks a million!!!! :D


Advertisement