php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46694 $_POST variable behaves differently for form with 1 input than multiple
Submitted: 2008-11-27 03:23 UTC Modified: 2008-12-05 01:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: web at mshearn dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.2.6 OS: RedHat Linux 2.4.21 x86_64
Private report: No CVE-ID: None
 [2008-11-27 03:23 UTC] web at mshearn dot com
Description:
------------
Under PHP 5.2.6 the $_POST variable behaves differently for html forms with 1 input field than forms with more than one.  When there is only 1 field in a form the result of $_POST['field_name'] gets returned as:

     FIELD_VALUEfield_name=FIELD_VALUE

With multiple form fields the result is returned as you would expect:

     FIELD_VALUE

Reproduce code:
---------------
<html>
<head>
<title>PHP 5.2.6 Form $_POST Problem</title>
</head>
<body>
<?php
if ($_POST)
{
        print("Contents of \$_POST variable<br /><br />\n");

        $count = count($_POST);

        print("$_POST contains $count item(s).<br />\n");

        foreach (array_keys($_POST) as $key)
        {
         $$key = $_POST[$key];
         print "$key is '${$key}'<br />";
        }
}
?>
<hr width="200" align="left"/>
Form with 1 input field<br /><br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Field1: <input type="text" name="field1" value="value1"/><br />
    <input type="submit" value="Add" />
</form>
<br />
<hr width="200" align="left"/>
Form with 2 input fields<br /><br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Field2: <input type="text" name="field2" value="value2" /><br />
    Field3: <input type="text" name="field3" value="value3" /><br />
    <input type="submit" value="Add" />
</form>
</body>
</html>


Expected result:
----------------
... click 1st Add button ...
Contents of $_POST variable

Array contains 1 item(s).
field1 is 'value1'

... click 2nd Add button ...
Contents of $_POST variable

Array contains 2 item(s).
field2 is 'value2'
field3 is 'value3'

Actual result:
--------------
... click 1st Add button ...
Contents of $_POST variable

Array contains 1 item(s).
field1 is 'value1field1=value1'

... click 2nd Add button ...
Contents of $_POST variable

Array contains 2 item(s).
field2 is 'value2'
field3 is 'value3'

It works properly for PHP 5.2.4 on another server.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-27 11:53 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can't reproduce. If the snapshot doesn't fix it, provide a bit more information of your setup, f.e. what SAPI and webserver you're using.
 [2008-12-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 17:01:31 2024 UTC