Get Variables values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zanzo
    New Member
    • Mar 2008
    • 16

    Get Variables values

    I have two input textbox with the same name, when submiting the page I get only the value of the second textbox.

    how can i get the value of both fields???
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Give them different names.

    The form is using post submission and the values are being stored in the $_POST array. This means that the processing runs through the form and generates the first array element and puts the value in. Then it finds another text box with the same name and just updates the value.

    So, simply give them unique names.

    Cheers
    nathj

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Nathj's reply seems the best way to do this, but you could turn the names of the inputs into an array. If you add [] to the end of the names, php will recognise them as an array.

      Code:
      <input name="test[]" type="text" />
      <input name="test[]" type="text" />
      
      ...
      
      // then php can access them like
      $_POST['test'][0]; // first input
      $_POST['test'][1]; // second input

      Comment

      • zanzo
        New Member
        • Mar 2008
        • 16

        #4
        Actually, my concern that to get all values of this field,

        As in Asp,it is done this way the values are separated by commas, I thought that can be done in php!

        thanks anyway :D

        Comment

        • zanzo
          New Member
          • Mar 2008
          • 16

          #5
          Thanks a lot Markus, it is working :D


          best regards,
          zanzo

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by zanzo
            Thanks a lot Markus, it is working :D


            best regards,
            zanzo
            Good, good.

            See ya around.

            Comment

            Working...