Jump to content

Archived

This topic is now archived and is closed to further replies.

themag

Problems using $_POST - help needed!

Recommended Posts

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.ini

The 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,

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Thanks




Could be an apache setting or something else in my php.ini?

Share this post


Link to post
Share on other sites
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_ALL
That'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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.