Add some content to the web page you built for the previous assignment.
First, remove all style attributes and move them to a <style> region
in the page head.
Second, the new
page should be accessed by a URL that invokes a CGI program called cafe-2.php
or cafe-2.cgi. You may write the CGI program in PHP (preferably) or any
other language, including C, C++, Perl, Python, or Java.
(Check with us if you want to use a language not listed here.)
You may use language-specific libraries to help you parse parameters and
generate HTML code, preferably using a template scheme.
Invoking the CGI program as a URL without parameters should produce a page that
looks like the screenshot at
at http://www.cs.uky.edu/~raphael/courses/CS316/project2/asg.cafe-2.1.png.
As you see, the cafe's web page has gotten some new features and dropped some
old ones.
The text of each menu item can now be clicked, bringing up a similar page but
with the menu information shown, as in the screenshot at
http://www.cs.uky.edu/~raphael/courses/CS316/project2/asg.cafe-2.2.png.
Here are the menu items, descriptions, and prices.
| snacks | |||
| olive hash | mashed olives in gravy | $2.50 | |
| smarties | small savory bites | $1.00 | |
| clumpers | chocolate-covered raisins | $1.50 | |
| drinks | |||
| smoothie | peach and frog flavored | $5.54 | |
| milk | fresh from our cow | $2.50 | |
| water | guaranteed mostly pure | $0.50 | |
| mains | |||
| steak | primal rib | $20.50 | |
| fish | whatever we found at the market | $25.00 | |
| mac-n-cheese | always a winner! | $15.00 | |
| deserts | |||
| ice cream | durian or avocado | $5.00 | |
| shave ice | durian or avocado | $3.20 | |
| cake | dark forest | $4.00 | |
| for kids | |||
| mac-n-cheese | always a winner! | $5.00 | |
| small fry | most likely some fish | $5.00 | |
| takeout | |||
| empty box | recyclable | $0.30 | |
| pizza slice | vegan, white | $1.00 | |
| ice cream cone | durian or avocado | $5.00 | |
| inedible | |||
| beer stein | glass | $3.00 | |
| can holder | rubber | $2.00 | |
| napkins | 50, recycled | $1.00 | |
| poisonous | |||
| table cleaner | bottled | $10.50 |
There are no menu items for pets!
The CGI program uses
a mySQL database with a table called menu that
stores all the menu items. It has columns
category, item, description, and price.
The first three are of type TEXT; the last is of type DECIMAL(4,2).
A second table, called accesses, has two columns:
category and number, of type TEXT and SMALLINT.
It stores how many times each menu item has
been accessed; increase the number by 1 for each access.
You need to create and populate these tables once by using mysql directly from
the command line.
style= attributes; all style must be in the <style>
section in the <head> region.
?
in any mySQL statement that refers to data coming from the web page, then
prepare the statement, then execute it providing the actual values, like this:
$sql = "SELECT price FROM menu WHERE category = ?; $prepared = $pdo->prepare($sql); $prepared->execute([$valueFromHTMLform]);
accesses table as the
source of valid menu items.
abcd123).
abcd123 to your login name):
% mysql -h mysql.cs.uky.edu -Dabcd123-uabcd123-p [it will prompt for your password, initially 'u'+last 7 digits of your UKID] DESCRIBE menu; SELECT * FROM menu; QUIT;
If you do any extra credit, you must indicate that in your documentation if you want credit.
accesses table to
correspond to entries in the menu table.
AUTO_INCREMENT instead of arithmetic to modify the number
value in the accesses table.
start fresh button that resets the counts of accesses to 0.
Turn in your CGI program via Canvas. If you are using a template scheme that requires a separate file, include both your CGI program and the template file and submit as a ZIP file. Keep your personal mysql credentials in a separate file that your CGI program refers to, but do not submit that credentials file.