Page 1 of 2

passing variables using POST

Posted: Fri Jul 26, 2002 9:53 am
by boinnk
When I try to pass variables with a form using POST it doesn't work. GET works fine... I'm running the latest version (4.2.2?) and I'm aware of the register_globals change in PHP. What's wrong?

Posted: Fri Jul 26, 2002 9:58 am
by BDKR
Show us some code so we can help.

Later on,
BDKR

Posted: Fri Jul 26, 2002 10:01 am
by boinnk
<?

if(!empty($_GET))
extract($_GET);
if(!empty($_POST))
extract($_POST);

?>
<html>
<head>
<title>test</title>
</head>
<body>
<form action="test.php" target="_self" method="post">
<input type="text" value="<? echo $name; ?>" name="name"><br><br>
<input type="Submit">
</form>
</body>
</html>
Doesn't output "$name" when I submit...

Posted: Fri Jul 26, 2002 10:18 am
by BDKR
Wow. I see what you're saying now. Well, I don't see an error as such, but let's see if we can debug a little. Why not echo some stuff back to the screen so that you can see what your script is doing in key places. How about something like this.

Code: Select all

if(!empty($_GET))
    &#123; 
    extract($_GET);
    echo $_GET; echo "<br>";
    &#125;
if(!empty($_POST))
    &#123;
    extract($_POST);
    echo $_POST&#1111;"name"]; echo "<br>";
    &#125;


At least this way we can be sure that the name var is getting into the POST array.

You can also try this too...

Code: Select all

<input type="text" value="<? echo $_POST&#1111;"name"]; ?>" name="name"><br><br>
Of course, this would defeat the purpose of using extract, but maybe we can get an idea of what is happening.

Later on,
BDKR

Posted: Fri Jul 26, 2002 10:20 am
by RandomEngy
Does the value stay in the field when you submit?

I tested the code, and it did for me, which is what the script is supposed to do. If you want to echo $name out in a place other than the default value for the form, just put another echo $name; statement outside the form.

Posted: Fri Jul 26, 2002 10:43 am
by boinnk
Nothing happens when I enter your code BDKR. Using GET it outputs 'Array' as it's supposed...
Still nothing using POST.
RandomEngy, yea it's supposed to stay in the field or anywhere... The problem is that when Im using post to send variables it wont work!

Posted: Fri Jul 26, 2002 10:51 am
by boinnk
Could it be an Apache related problem? Or is it something I need to change in my php.ini file?
Im using PHP version 4.2.2-dev and Apache 2.0.39.

Posted: Fri Jul 26, 2002 11:06 am
by twigletmac
Try:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
What's your error reporting set at? If it's not at the highest level bump it up and maybe something else will come to light.

Mac

Posted: Fri Jul 26, 2002 11:13 am
by boinnk
Error reporting is E_ALL. And I don't get any errors or warnings.

Code: Select all

echo '<pre>'; 
print_r($_POST); 
echo '</pre>';
Just outputs
'Array
(
)'

Posted: Fri Jul 26, 2002 11:25 am
by twigletmac
Well there is a $_POST array, which of course isn't terribly helpful as it seems to exist most of the time anyway... Have you tried with more form elements, perhaps adding a name and value to the submit button?

Mac

Posted: Fri Jul 26, 2002 11:32 am
by boinnk
Yes Ive tried renaming the Submit button and everything else I can think of. :(

Posted: Fri Jul 26, 2002 12:56 pm
by RandomEngy
I'm convinced it isn't a coding problem, but rather an apache-php configuration or installation problem. It seems the server is simply not receiving/processing the post data. However I'm far from an expert in that field, so someone else will have to answer that.

Posted: Fri Jul 26, 2002 1:30 pm
by boinnk
Is this the wrong place to be asking about this sort of problem? Am I the only one who has had this irritating problem??

Posted: Fri Jul 26, 2002 2:02 pm
by llimllib
It's the right place for it, but I just don't think any of us have seen this problem before.
I suggest you try different forms, try different browsers, try reinstalling PHP, try reinstalling your web server (in that order, probably) to see if you can use any of those to gain insight into the problem. Either your web browser is not sending the post variables or your web server is not letting PHP have them, it sounds like. try putting the variable checking on another page. try removing the target= from the form tag. Try everything that doesn't even make sense, because it may just be the thing that gives you an insight into the problem.
Also, if you want to really learn something, and you're already pretty good with computers, download a packet sniffer (http://www.ethereal.org is the best IMHO) and see if the variables are getting sent out of your browser. Then you can point your debugging at the PHP or the HTML to find the issue.
To sum up, try everything, just go until the point that you're about to tear your hair out, and then usually things fall into place.

Posted: Fri Jul 26, 2002 2:15 pm
by boinnk
Ill go through it again.
And I hope u ment ww.ethereal.com :)
Thanks for the help anyways.