this is not working properly

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

Post Reply
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

this is not working properly

Post by harsha »

<?php
$frm = $HTTP_GET_VARS['frm'];
$he= $HTTP_POST_VARS['he'];
switch ($frm)
{
case 'ome':
echo "<h1>this is the view page</h1>";
break;

case 'calc':
echo "aaa";
break;

default:
echo "<form action=\"{$PHP_SELF}?frm={$_POST['he']}\" method=\"post\">";
echo <<< HEHE
<input type="radio" name="he" value="ome" CHECKED><br>
<input type="radio" name="he" value="calc"><br>
<input type="submit" name="submit"><br>
HEHE;
echo "</form>";

break;

}
?>
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

what exactly is your error? am thinking it is this

Code: Select all

echo <<< HEHE 
<input type="radio" name="he" value="ome" CHECKED><br> 
<input type="radio" name="he" value="calc"><br> 
<input type="submit" name="submit"><br> 
HEHE;
maybe try this

Code: Select all

echo "<<< HEHE 
<input type="radio" name="he" value="ome" CHECKED><br> 
<input type="radio" name="he" value="calc"><br> 
<input type="submit" name="submit"><br> 
HEHE";
or alternatively

Code: Select all

?>
<<< HEHE 
<input type="radio" name="he" value="ome" CHECKED><br> 
<input type="radio" name="he" value="calc"><br> 
<input type="submit" name="submit"><br> 
HEHE
<?
User avatar
harsha
Forum Contributor
Posts: 103
Joined: Thu Jul 11, 2002 1:35 am
Location: Bengaluru (Bangalore) > Karnataka > India

problem is switch case

Post by harsha »

the problem is that if i submit the form the value in the radio button is
"ome" and the calc is not displayed even if i the calc radio button select
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

no, his heredoc syntax is correct. its something else. my guess would be the way he uses the predefined global variables (ie. $HTTP_POST_VARS, $_POST, etc.) you should choose one or the other and stick with it. chances are that is what is messing your script up.

but again it would be helpful if you explained what your specific problem was and not just spit out code to us.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

hmm, ok, didn't know about heredoc...anyway, I think I figured out whats up.

when its first submitted, its using action $PHP_SELF?frm= because nothing has been assigned to $_POST['he'] yet, so its a null string. and in the switch statement it uses $frm as the case to check, which the first time its submitted is empty, so goes back to default.

if you submit a second time, it works just fine.
Post Reply