473,503 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The $_POST array

I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
Nov 10 '05 #1
6 36202
IWT

Jørn Dahl-Stamnes wrote:
I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?


Try this:

foreach($_POST as $key => $value)
echo $key."=".$value;

Nov 10 '05 #2
IWT wrote:

Jørn Dahl-Stamnes wrote:
I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?


Try this:

foreach($_POST as $key => $value)
echo $key."=".$value;


Tried that too. Still no output...

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
Nov 10 '05 #3
Jørn Dahl-Stamnes wrote:
I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?


Can't think of anything but:
- it's a bug in your php version...,
- echo is buffered and/or redirected and print_r is not,
- "list" or "each" are redefined as constants earlier,
- the contents of $key or $val are preventing output.

If the last point, try using htmlspecialchars().

--
E. Dronkert
Nov 10 '05 #4
Ewoud Dronkert wrote:
Jørn Dahl-Stamnes wrote:
I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?


Can't think of anything but:
- it's a bug in your php version...,
- echo is buffered and/or redirected and print_r is not,
- "list" or "each" are redefined as constants earlier,
- the contents of $key or $val are preventing output.


Seems like a bug to me. I tried this:

$text = print_r ($_POST,true);
echo $text;

and it worked OK. So I'm able to get around this possible bug.

--
Jørn Dahl-Stamnes
http://www.dahl-stamnes.net/dahls/
Nov 10 '05 #5
Jørn Dahl-Stamnes wrote:
I got the following code:

reset ($_POST);
while (list($key,$val) = each($_POST))
{
echo "$key => $val\n";
}

But this prints out nothing. If I replace the code above with:
print_r ($_POST);

I can see the content of the $_POST array. Why?


Try this:

$ar=$_POST;
while (list($key,$val) = each($ar))
{
echo "$key => $val\n";
}

IIRC, older PHP versions had a problem with using the each function (and
the foreach) with any of the superglobal arrays...

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Nov 10 '05 #6
Justin Koivisto wrote:
IIRC, older PHP versions had a problem with using the each function (and
the foreach) with any of the superglobal arrays...


I thought that might be the case, but couldn't find anything with some
quick searches earlier (googled "php list each superglobal" and looked at
the comments at php.net/each).

--
E. Dronkert
Nov 10 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3149
by: Raptor | last post by:
I'm using a single script to generate a table with <input>s in each row. I fill the array with initial values, then write it out to the table and let the user edit the values. Something like: ...
12
5986
by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an invalid datatype. It is an array and if I copy...
11
3432
by: Adrian Parker | last post by:
Is it possible to click on a button, and not have it's value and name stored in _POST? I have this script with a button on it. When you click the button, the page posts to itself. The first...
15
7124
by: zorro | last post by:
greetings... I'm wondering what more advanced coders would think ot this: $_POST = clean($_POST); and now I can use POST directly: $sql= "select * from T1 where myvar='$_POST' " ;
7
2473
by: Dynamo | last post by:
I am using values stored an $_POST array to display records from a table before asking the user if he is sure he wants to delete them. If the user confirms then the records are deleted. Without...
1
6985
by: RDizzle | last post by:
okay. so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL values for all posted vars. What's the deal? ...
6
1373
by: comp.lang.php | last post by:
I have no idea why this is happening and I need someone to explain this to me at the simplest level absolutely possible (pretend I'm a 10-year old and explain it that way, please!) This class...
5
2283
by: comp.lang.php | last post by:
// NEW 11/27/2006: FINALLY, IF YOU ADDED OR DELETED OR DID ANY KIND OF FORM ACTION SUCCESSFULLY, DON'T RE-DISPLAY THE NEW EXPENSE ITEMS VIA $_POST if ($_POST && (!is_array($leaseObj->errorArray)...
5
3854
Tarantulus
by: Tarantulus | last post by:
Hi, ok, quick description of the problem, I'm trying to reference the postdata from some checkboxes. Unfortunately the checkboxes are dynamically generated therefore I don't know how many there...
7
5169
by: lawpoop | last post by:
Hello all - Is there a way to get a nested array in a $_POST variable? I have a form where there are several questions, each one corresponding to a database row. On submission of the form, I...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.