By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Cannot read information from form using POST or GET ($_Post is empty)

P: n/a
I am having problems in my php code. I am relatively new to php but I
know some basics.

This is the problem:

when i try to echo some information that is typed into form back to
the screen i get absolutely nothing. It seems like $_POST['name'] is
an empty string, along with $_POST and $_GET['name'].

I looked around to see if someone else had the same problem and found
that some people's code didn't work because of IE6. but i also tried
mine on Netscape and i got the same problem.

So why is $_POST empty after posting information. Even $_GET was
empty.

any help is appreciated.
all of those returned empty

echo $_POST;
echo $_POST['name'];
echo $_GET['name'];

here is the code:
the code was originially meant to send an email but i commented the if
statement out to see why it wasn't working

<html>
<head><title>Feedback</title></head>
<body>

<?php

// Handle POST method.
//if ($_POST)
//{

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

// Compose simple text message:
$message = "Message from $name
($email)\n\nComments:\n\n$comments";

// Send message to bo*@microsoft.com
mail("em***@email.com", "Feedback", $message);

// Thank the generous user
echo "<h1>Cheers!</h1>\n";
echo $_POST;
echo $_POST['name'];
echo $_GET['name'];
// }
//else
//{
echo($_POST);
echo($_POST['name']);
// mail("kr******@hotmail.com", "Feedback", $message);

echo("yo");
?>

<h1>Feedback</h1>

<form action="<?=$PHP_SELF ?>" method="Post">

<p>Name: <input type="text" name="name" /></p>

<p>Email: <input type="text" name="email" /></p>

<p>Comments:</p>
<p><textarea name="comments"></textarea></p>

<p><input type="submit" value="Send!" /></p>

</form>

<?php

// }

?>

</body>
</html>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Kevin schrieb:
when i try to echo some information that is typed into form back to
the screen i get absolutely nothing. It seems like $_POST['name'] is
an empty string, along with $_POST and $_GET['name'].


Are you sure that you don't use an outdated PHP version?

Matthias
Jul 17 '05 #2

P: n/a
On 30 Jun 2004 14:50:30 -0700, kr******@hotmail.com (Kevin) wrote:
So why is $_POST empty after posting information. Even $_GET was
empty.


Which version of PHP?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3

P: n/a

"Kevin" <kr******@hotmail.com> wrote in message
news:de**************************@posting.google.c om...
I am having problems in my php code. I am relatively new to php but I
know some basics.

This is the problem:

when i try to echo some information that is typed into form back to
the screen i get absolutely nothing. It seems like $_POST['name'] is
an empty string, along with $_POST and $_GET['name'].

<snip>

Superglobals ($_GET, $_POST, etc) are available at all scopes regardless of
configuration, so this is odd.

Couple of things that might help you in debugging this and everything else
ever:
1) When printing arrays, use print_r() instead of print() - this will expand
the contents out instead of printing the oh-so-helpful "Array". I always
prefix it with echo "<pre>"; and postfix with echo "</pre>"; to get the
formatting right.
2) Try using $_REQUEST to avoid any confusion about $_GET vs $_POST.
3) Try turning error output on: error_reporting(E_ALL); in the first line of
code under debugging.
4) Try the following:
echo "<pre>"; print_r($GLOBALS); echo "</pre>";
You ought to see SOMETHING in the output you recognise.

HTH
Garp
Jul 17 '05 #4

P: n/a
On Wed, 30 Jun 2004 14:50:30 -0700, Kevin wrote:
all of those returned empty

echo $_POST;
echo $_POST['name'];
echo $_GET['name'];


What output *are* you getting? "echo $_POST" or "echo $_GET" should at
least print the word "Array" to the screen.

Is your code even being parsed through the PHP parser?

Try "View Source" in your browser to see.

--
Jeffrey Silverman
je*****@pantsjhu.edu
Drop "pants" to reply by email

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.