943,816 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1659
  • PHP RSS
Oct 17th, 2008
0

PHP $POST and Input Order

Expand Post »
Hello,
I have a question about PHP. I realized that you can use the POST variable to get data from a form submitted with the type post, but does the order of the fields matter. Example:

index.html:
HTML Syntax (Toggle Plain Text)
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Form</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <FORM name='test' action='submit.php' method='post'>
  7. Name: <INPUT type='text' name='name' /><br />
  8. Programming Language <INPUT type='text' name='lang' /><br />
  9. <INPUT type='submit' value='submit' />
  10. </FORM>
  11. </BODY>
  12. </HTML>
Here's the code for submit.php:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //This code works
  3. echo $_POST['name'];
  4. echo "<br />"
  5. echo $_POST['lang'];
  6.  
  7. //But if I flip the two, it doesn't.
  8. echo $_POST['lang'];
  9. echo "<br />"
  10. echo $_POST['name'];
  11. ?>
My question is: Why does flipping the two POST vars make this code not work? If there is a way (besides of course writing it as the values are ordered, which will be hard since I am not sure what order the form's elements will be in) to get by this? Thanks Everyone for your great help!!!
Last edited by FlashCreations; Oct 17th, 2008 at 11:56 pm.
Similar Threads
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Oct 18th, 2008
1

Re: PHP $POST and Input Order

Hello,
I have a question about PHP. I realized that you can use the POST variable to get data from a form submitted with the type post, but does the order of the fields matter. Example:

index.html:
HTML Syntax (Toggle Plain Text)
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Form</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <FORM name='test' action='submit.php' method='post'>
  7. Name: <INPUT type='text' name='name' /><br />
  8. Programming Language <INPUT type='text' name='lang' /><br />
  9. <INPUT type='submit' value='submit' />
  10. </FORM>
  11. </BODY>
  12. </HTML>
Here's the code for submit.php:
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. //This code works
  3. echo $_POST['name'];
  4. echo "<br />"
  5. echo $_POST['lang'];
  6.  
  7. //But if I flip the two, it doesn't.
  8. echo $_POST['lang'];
  9. echo "<br />"
  10. echo $_POST['name'];
  11. ?>
My question is: Why does flipping the two POST vars make this code not work? If there is a way (besides of course writing it as the values are ordered, which will be hard since I am not sure what order the form's elements will be in) to get by this? Thanks Everyone for your great help!!!
there is no limitation with order , the post values come in an array and you can always access any element of an array. try print_r($_POST); and you will get clear idea. May be its an ; that you missed after echo "</br" that is creating problem.
Reputation Points: 11
Solved Threads: 1
Newbie Poster
adilkhan is offline Offline
1 posts
since Oct 2008
Oct 18th, 2008
1

Re: PHP $POST and Input Order

yes, in POST variable are stored in a array called $_POST...so we can retrieve them with key like $_POST['lang']; or $_POST['name']; or some thing...No matter of order...
or As adilkhan said,try to print print_r($_POST);...
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Oct 18th, 2008
0

Re: PHP $POST and Input Order

Ok thanks for the help!!
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Oct 20th, 2008
0

Re: PHP $POST and Input Order

just put ; at the end in your code at echo <echo "<br />" will give u result
Last edited by rohitrohitrohit; Oct 20th, 2008 at 5:58 am.
Reputation Points: 15
Solved Threads: 5
Junior Poster
rohitrohitrohit is offline Offline
120 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Installing PHP on Windows XP Pro with IIS
Next Thread in PHP Forum Timeline: Large File Download





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC