Using foreach with a form

Discussion in 'PHP' started by dotson83, Jun 20, 2007.

  1. #1
    Ok I'm tring to use foreach to get form data but all I get is "submit submit". What's wrong?

    Here is the code...
    <?php
    foreach($_GET as $key=>$val);
    {echo "$key  $val";
    }
    ?>
    
    PHP:
     
    dotson83, Jun 20, 2007 IP
  2. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Might want to show your form HTML.
     
    mrmonster, Jun 20, 2007 IP
  3. dvd871

    dvd871 Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Your basic code is off, should be like this:
    
    <?php
    foreach($_GET as $key=>$val) {
        echo "key: ".$key." val: ".$val;
    }
    ?>
    Code (markup):
    Also you form method must be GET, however most of the time you would use POST;
    <?php
    foreach($_POST as $key=>$val) {
        echo "key: ".$key." val: ".$val;
    }
    ?>
    Code (markup):
     
    dvd871, Jun 20, 2007 IP
  4. dotson83

    dotson83 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the help. It works now. I forgot about the "." thing. I was using _GET so I could see if the values were getting passed correctly. I normally use _POST though. Thanks again for your help.
     
    dotson83, Jun 20, 2007 IP