Question: Write the PHP code for two web pages for ordering food from an online store. The first page you will write is a form named

Write the PHP code for two web pages for ordering food from an online store. The first page you will write is a form named order.php that allows the user to choose what kind of food to buy and how many to buy. In your form, include a drop- down menu of food items available. Include a text box for the user to enter a quantity of the item to purchase (2-characters-wide), and an Order button to submit the form. The form should look like this:

Write the PHP code for two web pages for ordering food from

The food items to list should be based on what JPG food images are available in the current directory. For example, if the current directory contains apple.jpg and steak.jpg, then apple and steak appear in the drop-down list.

The second page you will write is named order-submit.php. The form in order.php submits its data as a POST request to order-submit.php. The output of order-submit.php is an HTML page fragment, a single paragraph indicating information about the order as described below.

The stores current inventory is stored in a file named inventory.txt on the server in the current directory. Each line of the file represents one item available in the store, its quantity available, and its price per unit, separated by tabs. Create your own inventory file. Here is an example inventory:

apple 4 1.00

chicken 1 3.25

cookie 38 0.25

milk 9 4.50

tomato 27 0.50

In general your task is to look up the price per unit of the item the user is ordering,

and use this price to compute the total order cost. For example, if the item costs

$0.50 and the user orders 7 of them, the total order is 7 * 0.50 = $3.50.

The pages output in the general successful case is to inform the user that the order

was successful, display the total order cost (you do not need to round it), and show

the user a series of images representing what was ordered. For example, if the user

orders 4 apples, your output should display 4 copies of apple.jpg:

an online store. The first page you will write is a form

Here is another output from ordering 15 of the item cookie. (the output wraps to

the next line in the browser) :

named order.php that allows the user to choose what kind of food

The store is only able to complete an order if that food item is in the inventory and the store has enough of that item in stock. For example, if the inventory matches the above text file (which has 9 milk in stock), and the user tries to order 10 of milk, the following error should be displayed:

to buy and how many to buy. In your form, include a

If an item is not present in the inventory file, assume that its quantity available in

stock is 0 and display the same sort of error message.

Food item: milk Quantity: 10 Order

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!