Cannot read $_POST information
Posted by: NielsWesterneng (---.chello.nl)
Date: November 15, 2009 04:09PM

The problem started when I was working on my MacBook, which I bought recently. The Mac version (MAMP) was not able to read information I sent via the $_POST method. I tried the same script on my WAMP on Windows and it didn't work either. I made a new very simple submit script, and it didnt work. I uploaded that script on my webserver and it worked perfectly. Here's the code.

<?php
if(isset($_POST['testfield'])){ echo "TEST: ".$_POST['testfield']; }
?>
<form method="post" name="test" action="">
<input type="text" name="testfield" /><input type="submit" value="Test" />
</form>

Why doesn't it work? Why can't I read $_POST information? Could anybody help me out? smiling smiley

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: c2dan (---.15-1.cable.virginmedia.com)
Date: November 15, 2009 07:00PM

Nothings wrong with that code. It should work fine.

Make sure you're saving this file in C:/wamp/www and that you're going to [localhost] to run script

Do not open the file directly in to your browser.

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: NielsWesterneng (---.chello.nl)
Date: November 15, 2009 11:38PM

There is indeed nothing wrong with the script, as it does work on my real webserver. As for the localhost server, it doesn't. Both on MAMP and the latest Wampserver version. Everything else works, but I just can't read $_POST information. Could it be a setting of some sort? There must be something.

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: toumimi (---.lv.lv.cox.net)
Date: November 15, 2009 11:56PM

Are you sure you are loading it from 'http://localhost/your_project/your_file.php'
Your file should be a .php file
Then try by putting an action in the form action (action="your_file.php"winking smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: yfastud (Moderator)
Date: November 16, 2009 05:51AM


Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: NielsWesterneng (---.chello.nl)
Date: November 16, 2009 11:06AM

I'm absolutely sure I'm running it on localhost. The database works and heck, all other stuff does work! Except for forms.

The code is also 100% correct, it works on the webserver. If I add an action, for example action="login.php" it does go to login.php, but I just can't read the $_POST globals.

Is there anything I can do to activate these globals? Can they even be disabled?

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: mjh_ca (---.hsd1.tn.comcast.net)
Date: November 17, 2009 12:06AM

Random troubleshooting ideas here..

Try doing:

<?php var_dump($_POST); ?>

and

<?php var_dump($_SERVER['REQUEST_METHOD']); ?>


to inspect what is in the array and to confirm the data is actually being POSTed. Maybe a typo somewhere that we aren't seeing.

Do you have any obscure PHP extensions enabled that might be interfering with the request parameters? (I've never seen this, but I guess it is possible...)

Try submitting the form with Firefox and Firebug enabled and confirm that the data you expect is actually being posted by using Firebug to inspect the posted values. Maybe a typo somewhere in the HTML..

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: NielsWesterneng (---.chello.nl)
Date: November 17, 2009 08:50PM

Thanks for the help, but unfortunately it's not solving anything. The script works perfectly on my webserver so there's nothing wrong with the script. There is someting wrong with Wampserver, or a particular setting is wrong (though I just reinstalled it and I use standard settings).

<?php var_dump($_POST); ?>

gives a NULL, which indicated there's just no information sent via the form. Strange =/

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: stevenmartin99 (92.251.255.---)
Date: November 18, 2009 09:48AM

there is nothing wrong with wamp as nobody has had this issue before.. Everyone uses post with out issue.

Have u tried REQUEST and GET?

Try


<pre>
<?php
Print_r($_SYSTEM);
?>
</pre>

If this doesnt work then there is some issues and ul need to post up ur phpinfo()


Also make sure all of ur scripts have <?php and not <? Unless u turn on short_open_tags on the wamp menu left click wamp icon>php>php settings>short_open_tags

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: Drazzke (---.dynamic.mts.net)
Date: June 24, 2010 04:36AM

I realize that this topic is a few months old, but I just want to say that I have encountered exactly the same problem today while working on a project of mine. I haven't touched any of the settings, and it was working just a few days ago, but suddenly the $_POST globals weren't working. My code is perfectly fine - I uploaded it to a host I have and the code executed without a problem.

I even tried something as simple as

<?php
if(isset($_POST["test"])) { echo $_POST["test"]; }
?>
<form method="post">
<input type="text" name="test"/><input type="submit"/>
</form>

And still it didn't work.

I then went through php.ini to see if anything had been changed there, however everything looked fine and was in working order.

Finally, I decided to re-install WAMP as I really had no idea what to do further. It still didn't work.


So then I went into the WAMP php settings and found "register globals" and check it (it was unchecked) and then my code started working again. I don't have a good understanding of php.ini, so maybe that was in there originally and I just missed it. The odd thing is, is that I never changed any of these settings, so I have no idea why this happened.



Edited 1 time(s). Last edit at 06/24/2010 05:05AM by Drazzke.

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: June 24, 2010 06:52AM

you shud not turn it on


Your code is probably wrong cos its not being submitted from the previous page

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: Drazzke (---.static.mts.net)
Date: June 24, 2010 07:56PM

No, my code is fine. It works perfectly when I upload it to my host, however it didn't work with WAMP.

Also, what is wrong with enabling/turning on the register_globals?



Edited 1 time(s). Last edit at 06/24/2010 07:57PM by Drazzke.

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: June 24, 2010 08:12PM

This feature has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Webhosts have it turned on . which they shudnt..


Hence your code is not good code. it may work on the host but it wont run in wamp

<form method="post">
<input type="text" name="test"/><input type="submit"/>
</form>


you dont have an action in your form....

You shouldnt need to turn on Globals on for your code to work

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Cannot read $_POST information
Posted by: Drazzke (---.dynamic.mts.net)
Date: June 24, 2010 11:56PM

Ah, I didn't realize that forms required action. That clears up the issue I was having - thanks for going into a little more detail.

Cheers,
Noel.

Options: ReplyQuote


Sorry, only registered users may post in this forum.