General discussion

Locked

PHP script---working not correctly

By syedirfi ·
<?php
function display_form() {
global $PHP_SELF;
?>
<FORM TARGET="<?php echo $PHP_SELF; ?>" METHOD=GET>
Name: <INPUT TYPE=TEXT NAME="name"><BR>

Favorite Cheese: <INPUT TYPE=RADIO NAME="cheese" VALUE="brie">Very soft French Brie
<INPUT TYPE=RADIO NAME="cheese" VALUE="cheddar">Farmhouse English Cheddar
<INPUT TYPE=RADIO NAME="cheese" VALUE="mozzarella">Italian Buffalo Mozzarella


Favorite Times to Eat Cheese:
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="m">Morning
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="n">Noon
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="d">Dinner
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="l">Late night


<INPUT TYPE=HIDDEN NAME="stage" VALUE="results">
<INPUT TYPE=SUBMIT VALUE="Thanks!">
</FORM>
<?php
}
?>


<?php
function process_form() {
global $name;
global $cheese;
global $times;

if ($cheese == 'brie') { $cheese_message = 'I love brie.'; }
elseif ($cheese == 'cheddar') { $cheese_message = 'Cheddar is awesome!'; }
else { $cheese_message = 'Fresh mozzarella is divine.'; }


$favorite_times = count($times);

if ($favorite_times <= 1) {
$times_message = 'You should eat cheese more often.';
} elseif ($favorite_times > 1 && $favorite_times < 4) {
$times_message = 'Those are good times to eat cheese.';
} else {
$times_message = 'You are eating too much cheese.';
}


echo "Hello $name.";
echo "$cheese_message $times_message";
}


?>

<?php
if (empty($stage)) { display_form(); }
else { process_form(); }


?>

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Web Development Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums