Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to retrieve POST data?

Status
Not open for further replies.

alan123

MIS
Joined
Oct 17, 2002
Messages
149
Location
US
I have two php pages:
1)
<form method=post action="page2.php">
<input type=hidden name=a1 value=1 onclick="cal()">
<input type=hidden name=a2 value=2 onclick="cal()">
....
<input type=hidden name=a100 value=100 onclick="cal()">

2)on php2.php:
I can retrieve those data by using
$a1=$_POST['a1'];
...
$a100=$_POST['a100'];

Now I want to use FOR statement to get the data:
for ($i=1;$i<=100;$i++)
$a[$i]=$_POST['a'+$i]; ???this is not correct, I don't know how to get those data.

I know I can use array in form in 1st page, such as <input type=hidden name=a[1] value=1 onclick="cal()">
but it doesn't work in javascript, so I have to use variable a1, a2...a100, but have no idea how to get it on page2.php

Anybody can help me? thanks in advance.
 
You had almost everything right in your for statement, except one thing. As far as I know, you use a period to seperate things instead of a plus sign, like this:

Code:
for ($i=1;$i<=100;$i++)
$a[$i]=$_POST['a'.$i];

That should work. If not...well then I will just give up PHP forever.

Hope this helps! Post me back if it does.

Peace out,
Peace Co.
 
You need not use a for statement. I recommend to use foreach() instead - no counter necessary:
Code:
foreach ($_POST as $key=>$value){
   ... etc ...
}
However, that doesn't make much sense as you could acces the posted data in the superglobal array to begin with.

As for the JavaScript here's a tip: you can assign a different id which has no [] to the element.

HTML tip: double quote your values for the attributes. It's worthwhile and standards compliant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top