www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to post values into an array from a select list

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    How to post values into an array from a select list

    hello sirs,

    I have a question about arrays.

    For example, I have a select pull down list with like 10-items. A user can make a selection and click SUBMIT and I want the value selected to be stored in an array.

    Supposing the user does the above like thrice, I would want the three selections to be stored in an array. How do I do this?

    I am able to post a selection into an array, but if the user makes a new selection and hits the submit button, the previous value is replaced.

    Pls how do I do the above.
    regards

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,918
    One word: sessions.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    How do i posT?

  4. #4
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    As NogDog says, you'd most likely want to use sessions. This can be accomplished by submitting your form to a php script that adds the values into a session array.

    HTML Code:
    <form method="post" action="process.php">
        <input type="text" name="field1" />
        <input type="submit" value="Send!" />
    </form>
    process.php
    PHP Code:
    <?php
    session_start
    ();

    if (!empty(
    $_POST['field1']))
        
    $_SESSION['field1_val'] = $_POST['field1']; // This value can now be accessed on PHP pages.

    // Nothing can be outputted before this point or you'll get errors.
    // Basically don't try to echo stuff. :P
    header('Location: success.php');
    exit;
    success.php
    PHP Code:
    <?php
    session_start
    ();

    echo 
    'This is the final destination after submitting the form.<br />';
    echo 
    $_SESSION['field1_val'];

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles