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>
<HEAD>
<TITLE>Form</TITLE>
</HEAD>
<BODY>
<FORM name='test' action='submit.php' method='post'>
Name: <INPUT type='text' name='name' /><br />
Programming Language <INPUT type='text' name='lang' /><br />
<INPUT type='submit' value='submit' />
</FORM>
</BODY>
</HTML>

Here's the code for submit.php:

<?php
//This code works
echo $_POST['name'];
echo "<br />"
echo $_POST['lang'];

//But if I flip the two, it doesn't.
echo $_POST['lang'];
echo "<br />"
echo $_POST['name'];
?>

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!!!

Recommended Answers

All 4 Replies

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>
<HEAD>
<TITLE>Form</TITLE>
</HEAD>
<BODY>
<FORM name='test' action='submit.php' method='post'>
Name: <INPUT type='text' name='name' /><br />
Programming Language <INPUT type='text' name='lang' /><br />
<INPUT type='submit' value='submit' />
</FORM>
</BODY>
</HTML>

Here's the code for submit.php:

<?php
//This code works
echo $_POST['name'];
echo "<br />"
echo $_POST['lang'];

//But if I flip the two, it doesn't.
echo $_POST['lang'];
echo "<br />"
echo $_POST['name'];
?>

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.

commented: Thanks for the help! +1

yes, in POST variable are stored in a array called $_POST...so we can retrieve them with key like $_POST; or $_POST; or some thing...No matter of order...
or As adilkhan said,try to print print_r($_POST);...

commented: Thanks for the Help!!! +1

just put ; at the end in your code at echo <echo "<br />" will give u result

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.