PHP $POST and Input Order

Thread Solved

Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

PHP $POST and Input Order

 
0
  #1
Oct 17th, 2008
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:
  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:
  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.
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: adilkhan is an unknown quantity at this point 
Solved Threads: 1
adilkhan adilkhan is offline Offline
Newbie Poster

Re: PHP $POST and Input Order

 
1
  #2
Oct 18th, 2008
Originally Posted by FlashCreations View 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:
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: PHP $POST and Input Order

 
1
  #3
Oct 18th, 2008
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);...
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 184
Reputation: FlashCreations is an unknown quantity at this point 
Solved Threads: 15
FlashCreations's Avatar
FlashCreations FlashCreations is offline Offline
Junior Poster

Re: PHP $POST and Input Order

 
0
  #4
Oct 18th, 2008
Ok thanks for the help!!
FlashCreations
(aka PhpMyCoder)

About Me | My Blog | Contact Me
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 42
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 2
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

Re: PHP $POST and Input Order

 
0
  #5
Oct 20th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC