We help IT Professionals succeed at work.

Array display PHP/.txt form

shareea asked
Last Modified: 2012-06-27
The else portion won't display with correct values:

<body bgcolor="#999966" text="#000000">
<h1><font face="Arial, Helvetica, sans-serif">SADA Restaurant</font></h1>

//create short variables
$meal_item = $_REQUEST['meal_item'];
$foodqlty = $_REQUEST['foodqlty'];
$servqlty = $_REQUEST['servqlty'];

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>";

echo "<p><i>Thanks for dining with us! Below is your receipt.</i></p>";

//display item(s) ordered

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_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);


Watch Question

Top Expert 2004

Will it display with incorrect values?
Unlock this solution and get a sample of our free trial.
(No credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.