Link to home
Start Free TrialLog in
Avatar of shareea
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]}</input><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[1]</input><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[2]</input><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[3]</input><br />";
echo "<input type='checkbox' name='meal_item[]' value ='$menu[$i]'>$menu[4]</input></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</input><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($meal_item);

for ($i=0; $i<$number_of_items_selected; $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>
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Will it display with incorrect values?
ASKER CERTIFIED SOLUTION
Avatar of dharmanerd
dharmanerd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial