• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 567
  • Last Modified:

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>
0
shareea
Asked:
shareea
1 Solution
 
Steve BinkCommented:
Will it display with incorrect values?
0
 
dharmanerdCommented:
Add quotes around the zeros.
if ($meal_item == '0' && $email == '0' && $foodqlty == '0' && $servqlty == '0')

I'm guessing your variable contains a string and the expression is saying something like $menu_item = 'blah'... 'blah' is not an integer so it must be zero.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now