passing variables using POST
Moderator: General Moderators
passing variables using POST
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?
Doesn't output "$name" when I submit...<?
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>
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.
At least this way we can be sure that the name var is getting into the POST array.
You can also try this too...
Of course, this would defeat the purpose of using extract, but maybe we can get an idea of what is happening.
Later on,
BDKR
Code: Select all
if(!empty($_GET))
{
extract($_GET);
echo $_GET; echo "<br>";
}
if(!empty($_POST))
{
extract($_POST);
echo $_POSTї"name"]; echo "<br>";
}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ї"name"]; ?>" name="name"><br><br>Later on,
BDKR
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try:
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
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';Mac
Error reporting is E_ALL. And I don't get any errors or warnings.
Just outputs
'Array
(
)'
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';'Array
(
)'
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
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.
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.