passing variables using POST

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

boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

passing variables using POST

Post 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?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Show us some code so we can help.

Later on,
BDKR
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post 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...
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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.
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post 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!
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post 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
(
)'
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post by boinnk »

Yes Ive tried renaming the Submit button and everything else I can think of. :(
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post 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.
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post 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??
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post 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.
boinnk
Forum Newbie
Posts: 22
Joined: Fri Jul 26, 2002 9:53 am
Location: Sweden

Post by boinnk »

Ill go through it again.
And I hope u ment ww.ethereal.com :)
Thanks for the help anyways.
Post Reply