Page 1 of 1

Trouble accessing form input

Posted: Tue Aug 11, 2009 4:46 pm
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>";
?>
 

Re: Trouble accessing form input

Posted: Tue Aug 11, 2009 4:55 pm
by aceconcepts
Try

Code: Select all

print_r($_POST);
This will output the all POST values.

Re: Trouble accessing form input

Posted: Tue Aug 11, 2009 5:05 pm
by foodgod
Aceconcepts,
Thanks for the reply! The print_r($_POST);, is that in place of the echo statements?

Re: Trouble accessing form input

Posted: Tue Aug 11, 2009 5:23 pm
by jackpf
Put it anywhere. It should show you the array keys of the post data, and what you should be posting.

Re: Trouble accessing form input

Posted: Tue Aug 11, 2009 6:59 pm
by aceconcepts
It's just a method to see if anything exists in the POST array.

Re: Trouble accessing form input

Posted: Tue Aug 11, 2009 8:29 pm
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?

Re: Trouble accessing form input

Posted: Wed Aug 12, 2009 5:17 pm
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!

Re: Trouble accessing form input

Posted: Wed Aug 12, 2009 7:00 pm
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);

Re: Trouble accessing form input

Posted: Thu Aug 13, 2009 8:44 am
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:

Re: Trouble accessing form input

Posted: Thu Aug 13, 2009 9:09 am
by foodgod
Doesn't seem to be a browser issue. Downloading a third browser for testing. :banghead: