Credit Cards - Halloween Costumes - Car Loan - Credit Cards - Books

PDA

View Full Version : How to use a PHP function to covert this program?


sunnyboy1984
Mar 5th 2007, 10:23 am
Can anyone offer some advice about how to convert the following receipt code by using a function called
select_beverage($dinner)

The entree chosen through the HTML form should be passed into the $dinner parameter, and the result should be returned to the program to be processed with the rest of the receipt.


<ol style="font-size:16px;">

<li><h3>This is your receipt</h3>

<?
$my_Steak = "Steak";
$my_Salmon = "Salmon";
$my_BarbecuePork = "BarbecuePork";
$my_Chicken = "Chicken";

echo "<BR>Our meal includes ".$my_Steak.",
".$my_Salmon.", ".$my_BarbecuePork.", and ".$my_Chicken."!<br>";

?>

<?
$my_dinner = $_GET ["my_dinner"];


if ($my_dinner == "Steak")
{
echo "<i>Your chosen meal is steak.Your recommended drink is red wine</i>";

}
else if
($my_dinner == "Salmon")
{
echo "<i>Your chosen meal is salmon. Your recommended drink is white wine</i>";
}

else if
($my_dinner == "BarbecuePork")
{
echo "<i>Your chosen meal is barbecuepork. Your recommended drink is coke</i>";


}


else


{
echo "<i>Your chosen meal must be chicken.Your recommended drink is apple juice";

}
?>

<h3>Looking forward to your next visit :) </h3>



</ol>

This is the HTML code:


<body>
<h3>Please choose a entre for your dinner </h3>

<form method="GET" action="Lesson.php">
Your dinner:

<select name="my_dinner">
<option value="">Please choose...
<option value="Steak">Steak
<option value="Salmon">Salmon
<option value="BarbecuePork">BarbecuePork
<option value="Chicken">Chicken
</select>


<input type=submit value="SUBMIT">

</form>
</body>

nico_swd
Mar 5th 2007, 10:58 am
Like this?


function select_beverage($dinner)
{
switch ($dinner)
{
case 'Steak':
echo "<i>Your chosen meal is steak.Your recommended drink is red wine</i>";
break;

case 'Salmon':
echo "<i>Your chosen meal is salmon. Your recommended drink is white wine</i>";
break;

case 'BarbecuePork':
echo "<i>Your chosen meal is barbecuepork. Your recommended drink is coke</i>";
break;

default:
echo "<i>Your chosen meal must be chicken.Your recommended drink is apple juice";
}
}

sunnyboy1984
Mar 5th 2007, 11:03 am
But how to change the HTML? The value needs to be processed by the HTML form. use <select_name = "dinner">??

cowguru2000
Mar 5th 2007, 11:15 am
Make the form method POST and instead of $_GET[''], use $_POST['mydinner'].