php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19052 $_POST doesn't work correctly
Submitted: 2002-08-22 12:05 UTC Modified: 2002-09-27 13:06 UTC
From: awilliam at mdah dot state dot ms dot us Assigned:
Status: Not a bug Package: Apache2 related
PHP Version: 4CVS-2002-08-22 OS: Red Hat 7.3 Linux 2.4.18
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: awilliam at mdah dot state dot ms dot us
New email:
PHP Version: OS:

 

 [2002-08-22 12:05 UTC] awilliam at mdah dot state dot ms dot us
I am using PHP from http://snaps.php.net.  The version I downloaded is 200208220600.  I have an html file called insert_form.html and a php file called insert.php.  What happens is insert_form.html gets text input from a user and then passes the user's input into a variable using METHOD=POST in the html form.  Then in insert.php all it does is return the text the user submitted on insert_form.html.  Below is the sample code.  If you run it and look at the data returned by insert.php, for some reason, PHP is returning the value wrong.  It appears to return <value><name=value>.  For example if I type in PHPBUGVALUE then insert.php returns 
PHPBUGREPORTtestField=PHPBUGREPORT when it should just print PHPBUGREPORT.  If in the code below I change METHOD=POST to METHOD=GET in insert_form.php and $_POST to $_GET in insert.php then it works fine and insert.php prints PHPBUGREPORT.  Thank you for looking into the problem.

<!-- insert_form.html-->
<HTML>
<HEAD><TITLE>Insert Form</TITLE>
</HEAD>
<BODY>
<FORM ACTION="insert.php" METHOD="POST">
<P>Text to add:<br>
<input type=text name=testField size=30>
<p><input type=submit value="Insert Record"></p>
</FORM>
</BODY>
</HTML>
<!-- end insert_form.html-->

<!-- insert.php -->
<?php
echo "the value is $_POST[testField]<BR>";
?>
<!-- end of insert.php -->

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-22 12:09 UTC] rasmus@php.net
I don't see how this is possible.  Which version of Apache are you using?
 [2002-08-22 12:14 UTC] awilliam at mdah dot state dot ms dot us
I am using Apache 2.0.40.  It was compiled using ./configure --enable-modules=all

I compiled PHP using ./configure --enable-track-vars --with-mysql --with-mail
--with-apxs2=/usr/local/apache2/bin/apxs

If you need the output of phpinfo(); it is http://www.squeezer.net/phpinfo.php
 [2002-08-22 12:18 UTC] rasmus@php.net
Ah, ok, it is an Apache2-related issue then.  This stuff is still very experimental.  Use Apache 1.3 if you just want your stuff to work.  Otherwise dive into the code and let us know what the fix is.
 [2002-08-22 14:47 UTC] sander@php.net
Dupe of #19047.
 [2002-09-26 12:15 UTC] sniper@php.net
Most likely problem within the browser.
Also, try more recent versions of PHP and Apache2 if that
is not the case.

 [2002-09-27 13:06 UTC] awilliam at mdah dot state dot ms dot us
I just compiled apache 2.0.42 and php 200209270600 from snaps.php.net and still have the same error.  I tried it with Mozilla 1.1 and IE 5.5.
 [2002-12-11 12:02 UTC] lar3ry at emuck dot com
I think I found the failure mode.  The submit button in the example doesn't have a name attribute.  If you add a name attribute to the "Insert Record" field, the bug disappears and the $_POST array appears correct.  (I tried this using A/B comparisons between a page that worked and the example above until the example worked).

Could the work-around be to ensure that all form elements have name attributes?

Fixing this might be pretty important.  I'm probably not the only person stuck running RedHat 8.0, which uses Apache 2.0.40 and php 4.2.2, and the version of RH 8.1 beta that I've checked seems to have the same bug.  [sigh]

Anyway, here's the "corrected" version of the script which seems to work on my configuration:

<!-- insert_form.html-->
<HTML>
<HEAD><TITLE>Insert Form</TITLE>
</HEAD>
<BODY> 
<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
<P>Text to add:<br>
<input type=text name=testField size=30>
<p><input name=sfield type=submit value="Insert Record"></p>
</FORM>
</BODY>
</HTML>
<!-- end insert_form.html-->
 
<!-- insert.php -->
<?php
echo "the value is $_POST[testField]<BR>";
?>
<!-- end of insert.php -->
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC