PHP - same trivial code behaving differently in two places
June 11, 2006 12:48 PM
Subscribe
Short piece of PHP code - all it does is set a variable and POST it back to the same PHP code - that works when executed on my hosted web site, but doesn't work when executed on my local machine running XAMPP.
All I'm doing is setting a variable, and POSTing it to the same piece of PHP code, so that the first time the code executes (no variable set yet) one thing happens, and the second time the code executes (variable has now been set and POSTed) something different happens.
My web host is running PHP 4 on Apache on Linux, and locally I'm running PHP 5 on Apache on Windows (via XAMPP.)
I'd like to know how to fix the code so it works in both locations, if possible.
On my desktop all it does is keep going to Case (0) where the variable $answer has not been set. On my web host it progresses through the three cases each time you click the button, so after the second click it hits the place where it echoes DONE and finishes.
Warning: I'm self-taught - the whole thing may be a bad way of doing things. I'm willing to accept an alternate solution, but I'd still like to know why this doesn't work in both environments:
Test of Post
Testing Post
< ?php # if ($answer=1) { $switchflag=1; } if ($answer> 1) {
$switchflag = 2;
}
if (!isset($answer)) {
$switchflag = 0;
}
switch ($switchflag) {
case (0):
# Case where answer =0 never been through yet
echo "
First time through, because no value for answer has been passed.
";
echo "";
echo "";
echo "";
break;
}
switch ($switchflag) {
case (1):
echo "
Second time through because answer has been passed with a value of 1.";
echo "";
echo "";
echo "";
break;
}
switch ($switchflag) {
case (2):
# Last time through
echo "
DONE";
break;
}
?>
>
posted by lockedroomguy to computers & internet (22 comments total)
Sorry to waste your time.
posted by lockedroomguy at 12:51 PM on June 11, 2006