themag Posted October 27, 2006 Share Posted October 27, 2006 Please help – I am having problems using $_POST with PHP5. My Environment Spec: Win XP SP2, Apache 2.2.3, PHP 5, MySQL 5 (will eventually run on Linux)I have “register_globals = Off” and “file_uploads = On” in my php.iniThe following simple script works with GET but not with POST:<?php if (isset($_POST['submit'])) { echo "Hi ".$_POST['name']."!<br />"; echo "The address ".$_POST['email']." will soon be a spam-magnet!<br />"; }?><form action="subscribe.php" method="post"><p> Name:<br /> <input type="text" name="name" size="20" maxlength="40" value="" /></p><p> Address:<br /> <input type="text" name="email" size="20" maxlength="40" value="" /></p> <input type="submit" name="submit" value="Go!" /></form>Does anyone have any ideas what the problem might be? I tried doing some research online but couldn’t find anything.Any help much appreciated. Cheers, Quote Link to comment Share on other sites More sharing options...
Caesar Posted October 27, 2006 Share Posted October 27, 2006 Put this all in one file and test to see if it passes the value:[code]<?php if($_POST[submit] != '') { $test = $_POST[butt]; echo"$test"; } echo" <table align=\"center\"> <form method=\"post\" action=\"$PHP_SELF\"> <tr><td>Text to test: </td><td><input type=\"text\" name=\"butt\"></td></tr> <tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Do It!\"></td></tr> </form> </table>";?>[/code] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 28, 2006 Share Posted October 28, 2006 you could just print your $HTTP_POST_VARS by going:[code=php:0]print_r($HTTP_POST_VARS);[/code] and see if it is getting any data. Quote Link to comment Share on other sites More sharing options...
themag Posted October 28, 2006 Author Share Posted October 28, 2006 Thanks both for your comments.Since I am using php5 I updated my php.ini (set register_long_arrays = On) to allow the use of $HTTP_POST_VARS. Unfortunately this just produced the following output when I post: Array ( ) i.e. there doesn't seem to be any data being POSTed.....With regards to the php script above I tried this but got the following errors:"Notice: Undefined index: submit in C:\Apache2.2\htdocs\subscribe2.php on line 3""Notice: Undefined variable: PHP_SELF in C:\Apache2.2\htdocs\subscribe2.php on line 13"So I changed the code to this:[code]<?php if (isset($_POST['submit'])) { $test = $_POST['butt']; echo"$test"; } $script = $_SERVER['PHP_SELF']; echo" <table align=\"center\"> <form method=\"post\" action=\"$script\"> <tr><td>Text to test: </td><td><input type=\"text\" name=\"butt\"></td></tr> <tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Do It!\"></td></tr> </form> </table>";?>[/code]This didn't display any value on the screen when I filled in the form with values and hit submit.....Could it be an apache setting or something else in my php.ini?ThanksCould be an apache setting or something else in my php.ini? Quote Link to comment Share on other sites More sharing options...
Kirtan Posted January 4, 2007 Share Posted January 4, 2007 Hi,With first script (not last post) use this line of code [code]<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">[/code]If you still get error message then in your php.ini file the error notificatication should be E_ALLThat's fine. DOn't change it. Add this line of code in your script (temporarily for dev. purpose)[code]error_reporting(E_ALL ^ E_NOTICE);[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.