If a form is submitted from an external site to my php page that uses the same parameter name for different values, how to get all submitted values and not just the last one?

Example:

Enter City: <input type="text" name="address"><br>
Enter State: <input type="text" name="address">

Thank you

    maybe as an array, not sure. Or the browser is unsure and only sends the last

      the name of the 2 text-input is the same, you must rename them:

      Enter City: <input type="text" name="address"><br>
      Enter State: <input type="text" name="address"> 
      

      to

      Enter City: <input type="text" name="address_city"><br>
      Enter State: <input type="text" name="address_state"> 
      

        Certainly the best solution would be to not have fields with the same name, or else use array style names and access them as additional dimensions to the $_POST array. But if you are stuck with that form for some reason, you can access the post data as a single URL query string via:

        $post_data = file_get_contents('php://input');
        

        You would then have to parse it yourself, probably [man]explode/man-ing on the "&" character and figure out how to handle the fact that you have two elements with the same key. The values will be urlencoded, so you will probably want to [man]urldecode/man them at some point.

          Thanks everyone. NogDog's solution is the best as I am indeed stuck with this form.

            Write a Reply...