Cannot access $_POST [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hypnotic_meat
Forum Newbie
Posts: 2
Joined: Sun Jun 07, 2009 7:01 pm

Cannot access $_POST [SOLVED]

Post 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.
Last edited by Benjamin on Sun Jun 07, 2009 11:35 pm, edited 2 times in total.
Reason: Changed code type from text to php.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Cannot access $_POST

Post 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.
Last edited by McInfo on Tue Jun 15, 2010 10:31 pm, edited 1 time in total.
hypnotic_meat
Forum Newbie
Posts: 2
Joined: Sun Jun 07, 2009 7:01 pm

Re: Cannot access $_POST

Post 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.
Post Reply