Hello, have a look at my code below:
the first one i have correct a few errors in yours to make it work as i expected.
[php]
Meal Receipt
<?php
// function select_beverage() // error here, passing a variable into the function below, but it can't accept it?
function select_beverage($dinner) // dinner.
{
if ($dinner == "5")
{
//$drink == "Pepsi"; // error here too many equal signs!
$drink = "Pepsi"; // corrected
}
elseif($dinner == "6")
{
$drink = "RC";
}
elseif($dinner == "7")
{
$drink = "Coke";
}
elseif($dinner == "8")
{
$drink = "Zero";
}
else
{
$drink = "None";
}
return $drink;
}
//return select_beverage($drink); // this line doesn't need to be here because you call it below?? see **
$dinner = $_GET["entree"];
$appetizer = "Salad";
$dessert = "Ice Cream";
$appetizer_price = .99;
$drink_price = .99;
$ice_cream_price = 1.99;
$sales_tax = 0.08;
$t = 0.15;
/*
** we will use this function call as it is setting a variable.
*/
$drink_capture = select_beverage($dinner); // Corrected: $dinner not $drink
$tmc = $appetizer_price + $drink_price + $dinner + $ice_cream_price;
$tax = $tmc * $sales_tax;
$tip = ($tmc + $tax) * $t;
$total_bill = $tmc + $tax + $tip
?>
<br/>
<ul>
<li> Entree: <?php echo $dinner; ?> </li>
<li> <?php echo $drink_capture." : ".$drink_price; ?> </li>
<li> <?php echo $dessert." : ".$ice_cream_price; ?> </li>
<li> <?php echo $appetizer." : ".$appetizer_price; ?> </li>
<li> Tax: <?php echo $tax; ?> </li>
<li> Tip: <?php echo $tip; ?> </li>
<li> Total: <?php echo $total_bill; ?> </li>
</ul>
[/php]
outputs:
[php]
Meal Receipt
* Entree: 5
* Pepsi : 0.99
* Ice Cream : 1.99
* Salad : 0.99
* Tax: 0.7176
* Tip: 1.45314
* Total: 11.14074
[/php]
Now my function is similar to yours:
[php]
Meal Receipt
<?php
function select_bev($drink) // dinner.
{
if ($drink == "Pepsi")
{
$xdinner = 5;
}
elseif($drink == "RC")
{
$xdinner = 6;
}
elseif($drink == "Coke")
{
$xdinner = 7;
}
elseif($drink == "Zero")
{
$xdinner = 8;
}
else
{
$xdinner = "None";
}
return $xdinner;
}
$drink = $_GET["drinks"]; // drinks
$xappetizer = "Salad";
$xdessert = "Ice Cream";
$xappetizer_price = .99;
$xdrink_price = .99;
$xice_cream_price = 1.99;
$xsales_tax = 0.08;
$xt = 0.15;
$xdinner = select_bev($drink); // drink
$xtmc = $xappetizer_price + $xdrink_price + $xdinner + $xice_cream_price; //total meal cost without tax
$xtax = $xtmc * $xsales_tax; //multiplying with tax to show tax on receipt
$xtip = ($xtmc + $xtax) * $xt; //total with tax times tip
$xtotal_bill = $xtmc + $xtax + $xtip
?>
<br/>
<ul>
<li> Entree: <?php echo $xdinner; ?> </li>
<li> <?php echo $drink." : ".$xdrink_price; ?> </li>
<li> <?php echo $xdessert." : ".$xice_cream_price; ?> </li>
<li> <?php echo $xappetizer." : ".$xappetizer_price; ?> </li>
<li> Tax: <?php echo $xtax; ?> </li>
<li> Tip: <?php echo $xtip; ?> </li>
<li> Total: <?php echo $xtotal_bill; ?> </li>
</ul>
[/php]
outputs:
[php]
Meal Receipt
* Entree: 7
* Coke : 0.99
* Ice Cream : 1.99
* Salad : 0.99
* Tax: 0.8776
* Tip: 1.77714
* Total: 13.62474
[/php]
and the HTML form
[php]
MEAL DEAL
Choice of Entrees:
Please choose...
Barbecue Pork
Steak
Chicken
Salmon
Choice of Drinks:
Please choose...
Pepsi
RC
Coke
Zero
[/php]
not sure if this was what you are looking for but i hope it helps.
by the way, i notice you use short open tags <? you should use the full <?php on all your scripts to ensure they work on servers with short open tags turned off (quite common!)