Can\'t connect with outside php file. The index page (index.php) isn\'t connecti
ID: 3728370 • Letter: C
Question
Can't connect with outside php file. The index page (index.php) isn't connecting with the Calculations.php page.
-----------Calculations.php----------
----------index.php----------
</html>
<?php //calculations.php //declare variables $order_total = ; $tax = $total * 0.65; //WA state sales tax as of 5/03/17 $grand_total = $order_total + $tax; //perform grand total calculations function grandTotal($price, $sides){//if ther are sides $grand_total = ($price + $Quantity) + ($sides * $quant); }//end grandTotal()Explanation / Answer
Your Calculations.php page is not connecting with index.php file because you have not used any form element in the index.php page that calls the Calculations.php file for the calculation of total prices. You only have one form element which is calling action_page.php for handling the messages for reservations.
You need to enclose your menu modal in a form element so that whatever food items the user selects from the given list, it is sent to the Calculations.php page where the calculation for the total prices is done.
This answer can be further improved if you can share a bit more detail on what you trying to achieve or what the task is. Also, it would help a lot if you could provide the details of what task the action_page.php is doing.
So according to me, you should modify your code as below:
In the index.php code you need to modify the menu modal part
<!--Modified code for menu modal -->
<div id="menu" class="w3-modal">
<form action="Calculations.php">
<div class="w3-modal-content w3-animate-zoom">
<div class="w3-container w3-black w3-display-container">
<span class="w3-button w3-display-topright w3-large">x</span>
<h1>Burger Types</h1>
</div>
<div class="w3-container">
<p><h5><input type="checkbox" name="order[]" value="tsoup">Tomato Soup <b>$2.50</b></h5></p>
<h5><input type="checkbox" name="order[]" value="csalad">Chicken Salad <b>$3.50</b></h5>
<h5><input type="checkbox" name="order[]" value="bandb">Bread and Butter <b>$1.00</b></h5>
</div>
<div class="w3-container w3-black">
<h1>Main Courses</h1>
</div>
<div class="w3-container">
<h5><input type="checkbox" name="order[]" value="gfishnp">Grilled Fish and Potatoes <b>$8.50</b></h5>
<h5><input type="checkbox" name="order[]" value="ipizza">Italian Pizza <b>$5.50</b></h5>
<h5><input type="checkbox" name="order[]" value="vegpasta">Veggie Pasta <b>$4.00</b></h5>
<h5><input type="checkbox" name="order[]" value="chickennpotato">Chicken and Potatoes <b>$6.50</b></h5>
<h5><input type="checkbox" name="order[]" value="dburger">Deluxe Burger <b>$5.00</b></h5>
</div>
<div class="w3-container w3-black">
<h1>Desserts</h1>
</div>
<div class="w3-container">
<h5><input type="checkbox" name="order[]" value="fsalad">Fruit Salad <b>$2.50</b></h5>
<h5><input type="checkbox" name="order[]" value="icecream">Ice cream <b>$2.00</b></h5>
<h5><input type="checkbox" name="order[]" value="ccake">Chocolate Cake <b>$4.00</b></h5>
<h5><input type="checkbox" name="order[]" value="cheese">Cheese <b>$5.50</b></h5>
</div>
</div>
</form>
</div>
Finally, you also need to modify Calculations.php as per the above form to handle the inputs.
The modified Calculations.php should look like as below:
<?php
//calculations.php
//declare variables
$order_total = 0; //variable to store the total price for the orders given
$price_map = getPriceMap(); //variable to store the mapping of items and their prices
$orderList = $_REQUEST['order']; //get the list of items ordered by the customer from the index.php page
$order_total = getOrderTotal($orderList, $price_map); //calculation of total price for the orders
$tax = $order_total * 0.65; //WA state sales tax as of 5/03/17. Calculation of tax
$grand_total = $order_total + $tax; //calculation of grand total , total price + tax
//echo $grand_total; //remove the comment in front of the line to see the grand total value (for debugging).
//do whatever you want with the grand total here.
//perform grand total calculations
function grandTotal($price, $sides)
{
// <---- this function is not used until you take sides as the orders ---->
//if ther are sides
$grand_total = ($price + $Quantity) + ($sides * $quant);
}
function getOrderTotal($item_arr,$price_map)
{
/**
* This function is used to calculate the total price of the items ordered by the customer
*/
$total = 0;
for($i=0;$i<count($item_arr);$i++)
{
$total = $total + $price_map[$item_arr[$i]];
//echo "adding price for ".$item_arr[$i]." as ".$price_map[$item_arr[$i]]."<br>";
//uncomment the above statement to use it for debugging, to see what items are being added to the price list.
}
return $total;
}
function getPriceMap()
{
/**
* This function creates a mapping of each item in the
* menu and their prices and returns an associative array containing
* the items and their prices
*/
$priceList = array();
$priceList["tsoup"] =2.50;
$priceList["bandb"] =1.00;
$priceList["csalad"] =3.50;
$priceList["gfishnp"] =8.50;
$priceList["ipizza"] =5.50;
$priceList["vegpasta"] =4.00;
$priceList["chickennpotato"] =6.50;
$priceList["dburger"] =5.00;
$priceList["fsalad"] =2.50;
$priceList["icecream"] =2.00;
$priceList["ccake"] =4.00;
$priceList["cheese"] =5.50;
return $priceList;
}
?>
If you are having problems with this answer, I urge you to elaborate the task and details of the program flow.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.