Trouble accessing form input

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
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Trouble accessing form input

Post by foodgod »

Hello Everyone,

I'm very new to PHP; just started yesterday! Anyway, I've been trying to run what should be a simple form reading process. I've searched the database for similar questions but can't seem to find one. I'm trying to read the name and message variables from an HTML form, but to no avail. Basically, the data from the form is not being printed out to the PHP file. I can't seem to find anything wrong with the code so I can only guess that it might be the php.ini file? The code I've been working on is below;the software in use are: PHP 5.2.9, Apache 2.2 on Fedora 10. I would greatly appreciate any help. Thank you!

Code: Select all

 
<html>
<head>
</head>
<body>
<form action="/cgi-bin/simpleform.php" method="POST">
<p> <strong>Name: </strong><br/>
<input type="text" name="user"/></p>
<p><strong>Message:</strong><br/>
<textarea name ="message" rows="5" cols ="40"></textarea></p>
<p><input type = "submit" value ="send"/></p>
</form>
</body>
</html>
 
For the PHP file:

Code: Select all

 
<?php
echo "<p>Welcome <b>".$_POST["user"]."</b>!</p>";
echo "<p>Your message is:<br/><b>".$_POST["message"]."</b></p>";
?>
 
Last edited by Weirdan on Wed Aug 12, 2009 7:31 pm, edited 2 times in total.
Reason: added [code=php] tags
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Trouble accessing form input

Post by aceconcepts »

Try

Code: Select all

print_r($_POST);
This will output the all POST values.
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Re: Trouble accessing form input

Post by foodgod »

Aceconcepts,
Thanks for the reply! The print_r($_POST);, is that in place of the echo statements?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Trouble accessing form input

Post by jackpf »

Put it anywhere. It should show you the array keys of the post data, and what you should be posting.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Trouble accessing form input

Post by aceconcepts »

It's just a method to see if anything exists in the POST array.
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Re: Trouble accessing form input

Post by foodgod »

I used the print_r($_POST); method and the return value was an empty array; array(). Could this be a php.ini configuration problem? I thought I might be able to enable register_globals to at least see some passing of variables but this did not work.Since this is a test server I'm not too concerned about safety. Are there some other configuration changes I may be able to make , regardless of security concerns, to make some kind of forward progress?
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Re: Trouble accessing form input

Post by foodgod »

I hacked and hacked and hacked some more and did some reconfiguring apache and php.ini and was able to get the GET option to work but not the POST option.. I think it's time to go back to PERL!
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Trouble accessing form input

Post by aceconcepts »

Try outputting the post array within the same page:

change:

Code: Select all

<form action="/cgi-bin/simpleform.php" method="POST">
to:

Code: Select all

<form action="" method="POST">
and then use

Code: Select all

print_r($_POST);
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Re: Trouble accessing form input

Post by foodgod »

Aceconcepts,

I used your suggestion a ran the code below:
<html>
<head>
</head>
<body>
<form action="" method="POST">
<?php print_r($_POST);?>
<p> <strong>Name: </strong><br/>
<input type="text" name="user"/></p>
<p><input type = "submit" value ="send"/></p>
</form>
</body>
</html>

The return value gave me nothing in return:
array()

Substituting in the following:
<form action="" method="Request">
<?php print_r($_REQUEST);?>

This snippet of code gave me:
array([user]=>variable)
The same holds true for the GET variable return. Basically, POST does not seem to be working! I could not find anything related to POST and not GET or REQUEST that I could be missing in the configuration files. I'm currently downloading other browsers to test if it's just a Mozilla issue. Not sure what else to do at this point. :banghead:
foodgod
Forum Newbie
Posts: 6
Joined: Tue Aug 11, 2009 3:46 pm

Re: Trouble accessing form input

Post by foodgod »

Doesn't seem to be a browser issue. Downloading a third browser for testing. :banghead:
Post Reply