shareea
asked on
Array display PHP/.txt form
The else portion won't display with correct values:
<html>
<head>
<title>Menu.php</title>
</head>
<body bgcolor="#999966" text="#000000">
<h1><font face="Arial, Helvetica, sans-serif">SADA Restaurant</font></h1>
<?php
//create short variables
$meal_item = $_REQUEST['meal_item'];
$foodqlty = $_REQUEST['foodqlty'];
$servqlty = $_REQUEST['servqlty'];
$DOCUMENT_ROOT = $_REQUEST['DOCUMENT_ROOT'] ;
if ($meal_item == 0 && $email == 0 && $foodqlty == 0 && $servqlty == 0)
{
//read array in text file
$menu = file("menu.txt");
$number_of_menu_items = count($menu);
echo '<p>What did you order?</p';
echo "<form name='mealform', method='post', action ='Menu.php'>";
echo "<p><input type='checkbox' name='meal_item[]' value ='$menu[$i]'>{$menu[0]}</i nput><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[1]</inp ut><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[2]</inp ut><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[3]</inp ut><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[4]</inp ut></p>";
echo "<p>How would you rate the food quality?</p>";
echo "<p><input name='foodqlty' type='radio' value='high'>High</input>< br />
<input name='foodqlty' type='radio' value='average'>Average</i nput><br />
<input name='foodqlty' type='radio' value='low'>Low</input></p >";
echo "<p>How would you rate the service quality?</p>";
echo "<p><select name='servqlty'>
<option value='high'>High</option>
<option value='average' selected>Average</option>
<option value='low'>Low</option></ select></p >";
echo "<p><input type='Submit' name='Submit' value='Submit'</input>";
}
else
{
echo "<p><i>Thanks for dining with us! Below is your receipt.</i></p>";
//display item(s) ordered
$number_of_items_selected= count($mea l_item);
for ($i=0; $i<$number_of_items_select ed; $i++)
{
//split up each line of items
$meal_price = explode( "\t", $meal_item[$i]);
//output each order
echo "$meal_price[0]
$meal_price[1]
$meal_price[2]";
}
$meal_total += $meal_price[2];
$tax_rate = 0.078375;
$tax_total = $meal_total * $tax_rate;
$grat_array = array( "high" => .20, "average" => .15, "low" => .10 );
$grat_percent = $grat_array[$foodqlty] + $grat_array[$servqlty];
$grat_total = $grat_percent * $meal_total;
$grat_nopercent = $grat_percent * 100;
$total_amount = $meal_total + $grat_total + $tax_total;
printf("<p>Meal: $%.2f</p>\n", $meal_total);
printf("<p>Gratuity ($grat_nopercent%%): $%.2f</p>\n", $grat_total);
printf("<p>Tax (7.8375%%): $%.2f</p>\n", $tax_total);
printf("<p>Total amount: $%.2f</p>\n", $total_amount);
}
?>
</body>
</html>
<html>
<head>
<title>Menu.php</title>
</head>
<body bgcolor="#999966" text="#000000">
<h1><font face="Arial, Helvetica, sans-serif">SADA Restaurant</font></h1>
<?php
//create short variables
$meal_item = $_REQUEST['meal_item'];
$foodqlty = $_REQUEST['foodqlty'];
$servqlty = $_REQUEST['servqlty'];
$DOCUMENT_ROOT = $_REQUEST['DOCUMENT_ROOT']
if ($meal_item == 0 && $email == 0 && $foodqlty == 0 && $servqlty == 0)
{
//read array in text file
$menu = file("menu.txt");
$number_of_menu_items = count($menu);
echo '<p>What did you order?</p';
echo "<form name='mealform', method='post', action ='Menu.php'>";
echo "<p><input type='checkbox' name='meal_item[]' value ='$menu[$i]'>{$menu[0]}</i
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[1]</inp
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[2]</inp
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[3]</inp
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[4]</inp
echo "<p>How would you rate the food quality?</p>";
echo "<p><input name='foodqlty' type='radio' value='high'>High</input><
<input name='foodqlty' type='radio' value='average'>Average</i
<input name='foodqlty' type='radio' value='low'>Low</input></p
echo "<p>How would you rate the service quality?</p>";
echo "<p><select name='servqlty'>
<option value='high'>High</option>
<option value='average' selected>Average</option>
<option value='low'>Low</option></
echo "<p><input type='Submit' name='Submit' value='Submit'</input>";
}
else
{
echo "<p><i>Thanks for dining with us! Below is your receipt.</i></p>";
//display item(s) ordered
$number_of_items_selected=
for ($i=0; $i<$number_of_items_select
{
//split up each line of items
$meal_price = explode( "\t", $meal_item[$i]);
//output each order
echo "$meal_price[0]
$meal_price[1]
$meal_price[2]";
}
$meal_total += $meal_price[2];
$tax_rate = 0.078375;
$tax_total = $meal_total * $tax_rate;
$grat_array = array( "high" => .20, "average" => .15, "low" => .10 );
$grat_percent = $grat_array[$foodqlty] + $grat_array[$servqlty];
$grat_total = $grat_percent * $meal_total;
$grat_nopercent = $grat_percent * 100;
$total_amount = $meal_total + $grat_total + $tax_total;
printf("<p>Meal: $%.2f</p>\n", $meal_total);
printf("<p>Gratuity ($grat_nopercent%%): $%.2f</p>\n", $grat_total);
printf("<p>Tax (7.8375%%): $%.2f</p>\n", $tax_total);
printf("<p>Total amount: $%.2f</p>\n", $total_amount);
}
?>
</body>
</html>
Will it display with incorrect values?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.