Hi! I am just learning php and i don’t think i know what I’m doing here. Any explanation or advice would be greatly appreciated.
I need a form to work. I have a list of menu items which I have put into an array and I need users to be able to make their selections through a checkbox form. Once they hit submit, it is suppose to bring them to a results page listing the selections made, and return the name, item cost of each of their selection as well as the total cost. My problem is that I am able to get the form to show up abut when it is submitted, the selection does not show up.
My two scripts are suppose to function in the same way as this website link http://itm325.itmbsu.net/jstudent/Examples/Ch5/tunacafe.php but I can’t get the code to work like it.
Here’s my menu page/initial form page:
[php]
Welcome to Sunset Bar & Grill!
<?php $menu = array('Cheeseburger','Chicken Salad','Chicken Noodle Soup', 'Supreme Pizza','Grilled Chicken Bagel','French Fries'); print 'Please select your order.'; for($i=0;$i< count($menu);$i++) { print " $menu[$i]"; print '
'; } ?> [/php] Here's the coding for my results page. [php]!DOCTYPE html> Order Results <?php include ("header.php") ?>
Here is your order:
<?php $prefer= $_post['prefer']; $menu = array('Cheeseburger', 'Chicken Salad', 'Chicken Noodle Soup', 'Supreme Pizza', 'Grilled Chicken Bagel', 'French Fries'); if (count($prefer) ==0){ print "Oh no! You did not order anything, yet. Please click on the Back button below to make your order again."; } else {
print "<h1>Your selections were</h1>
<ul>";
$item1 = "3.00";
$item2 = "2.00";
$item3 = "4.00";
$item4 = "2.25";
$item5= "3.75";
$item6= "2.50";
}
foreach ($prefer as $item) {
if ($item=="0") {
$itemcost = $itemcost + $item1;
print "<li>$menu[$item] $ $item1</li>";
}
if ($item=="1") {
$itemcost = $itemcost + $item2;
print "<li>$menu[$item] $ $item2</li>";
}
if ($item=="2") {
$itemcost = $itemcost + $item3;
print "<li>$menu[$item] $ $item3</li>";
}
if ($item=="3") {
$itemcost = $itemcost + $item4;
print "<li>$menu[$item] $ $item4</li>";
}
if ($item=="4") {
$itemcost = $itemcost + $item5;
print "<li>$menu[$item] $ $item5</li>";
}
if ($item=="5") {
$itemcost = $itemcost + $item6;
print "<li>$menu[$item] $ $item6</li>";
}
}
print "</ul>";
print 'Thank you! Your order will be ready soon.';
?>
<form method="link" action="menu.php">
<input type="submit" value="Back to Order">
</form>
[/php] I think its something about setting the values right but I don't know what to do right now about fixing this to work.