Page 1 of 1

Cannot access $_POST [SOLVED]

Posted: Sun Jun 07, 2009 7:10 pm
by hypnotic_meat
I'm trying to do something exceedingly simple and failing completely at it. I want to submit a form using the post method. Then, on the page the form data is posted to, I want to print *something* (anything at all will do at this point). Something like this:

HTML Code

Code: Select all

<form action="" method="post">
  <input type="text" id="blah"/>
  <input type="Submit" value="Save"/>
</form>
PHP Code

Code: Select all

if ($_POST)
  echo 'Information posted';
This is a trivial example and not at all what I want to do in my code, however, it's what I've reduced it to in an attempt to get things working. At the moment, whenever I submit the form, it just refreshes the page and nothing happens. Can anyone please offer some insight as to why this isn't working? It's absolutely infuriating me. Also, the action is left blank intentionally - I want to post the information to the current page.

Re: Cannot access $_POST

Posted: Sun Jun 07, 2009 7:25 pm
by McInfo
Save this file to your server's document root. If you don't know what that means, that is probably the problem.

test.php

Code: Select all

<pre><?php
print_r($_POST);
?></pre>
<form method="post" action="">
    <input type="text" name="txtExample" />
    <input type="submit" name="btnSubmit" value="Submit" />
</form>
Then go to http://localhost/test.php. After you submit the page, the array should have some values in it.

Edit: This post was recovered from search engine cache.

Re: Cannot access $_POST

Posted: Sun Jun 07, 2009 7:39 pm
by hypnotic_meat
Thanks for the quick reply. I compared your code to mine and found what my problem was. When I was declaring <input> elements, I was only giving them an id attribute, and $_POST requires name...I'm a dummy.