Jump to content

Problems using $_POST - help needed!


themag

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,
Link to comment
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]
Link to comment
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?

Link to comment
Share on other sites

  • 2 months later...
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.