Your task: 1. Convert cashier so that you can save data of customers' order into a database 2. Can display back the result 3. Provide the sample program for modification (please change the server name
MENU.php
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Menu </title>
<script src="cashier.js" type="text/javascript">
</script>
<link rel="stylesheet" type="text/css" href="style.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="print.css" media="print"/>
</head>
<?php
$host = "localhost";
$dbUsername = "id16858141_assignment2";
$dbPassword = "#9913Kino-#9913Kino";
$dbname = "id16858141_wad";
$connection = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error()); }
else {
$LOAD = "SELECT * FROM price";
$Found = $connection->query($LOAD);
echo "Harga Dari Database <br>" ;
print("No Food_Name Price <br>");
while ($row_price = $Found->fetch_assoc())
{
$dishes[]= $row_price['food_name'];
$price[]= $row_price['food_price'];
print($row_price['ID'] . " " . $row_price['food_name'] . " " . $row_price['food_price'] ."<br>" );
}
}
$connection->close();
// for ( $i = 0; $i < count( $dishes ); $i++ )
// print( "Element $i is $dishes[$i] <br />" );
?>
<body onload="init();">
<form name="frmCashier" action="insert.php" method="POST">
<table>
<caption id="username">Welcome to secret recipe</caption>
<tr>
<th>Item</th>
<th>Price/Unit</th>
<th>Quantity</th>
<th>Sub Total</th>
</tr>
<tr>
<?php print"<td> " . $dishes[0] ."</td>"; ?>
<!-- <td><input type="text" size="10" name="<?php $dishes[0] ?>" disabled="disabled" /> </td> -->
<td><input type="text" size="10" name="cc_price" value = "<?php print $price[0];?>" disabled="disabled" /></td>
<td><input type="text" style="text-align:center" size="10" name="cc_qty" onchange="cc();" /></td>
<td><input type="text" size="10" name="cc_sub_total" disabled="disabled" /></td>
</tr>
<tr>
<?php print"<td> " . $dishes[1] ."</td>"; ?>
<td><input type="text" size="10" name="fnc_price" value = "<?php print $price[1];?>"disabled="disabled" /></td>
<td><input type="text" style="text-align:center" size="10" name="fnc_qty" onchange="fnc();" /></td>
<td><input type="text" size="10" name="fnc_sub_total" disabled="disabled" /></td>
</tr>
<tr>
<?php print"<td> " . $dishes[2] ."</td>"; ?>
<td><input type="text" size="10" name="tn_price" value = "<?php print $price[2];?>" disabled="disabled" /></td>
<td><input type="text" style="text-align:center" size="10" name="tn_qty" onchange="tn();" /></td>
<td><input type="text" size="10" name="tn_sub_total" disabled="disabled" /></td>
</tr>
<tr>
<th colspan="3">TOTAL</th>
<th><input type="text" size="10" name="g_total" disabled="disabled" /></th>
</tr>
<tr>
<th colspan="4" align="center">
<input type="button" value="Print" onclick="window.print();" />
<input type="button" value="Reset" name="reset" onclick="init();" />
<input type="submit" value="Save to Database"></input>
</th>
</tr>
</table>
</form>
</body>
<!--- INSERT INTO `price` (`ID`, `food_name`, `food_price`) VALUES ('3333', 'Tomyam Noodles', '5.5'); -->
</html>
INSERT.php
<?php
$host = "localhost";
$dbUsername = "id16794774_pejal";
$dbPassword = "Faizal-12345";
$dbname = "id16794774_wad2021";
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$INSERT = "INSERT INTO 'food order' ('no', 'food_name', 'food_qty')" 'VALUES' 2 . $_POST['cc_qty'] . );
mysqli_query($conn,$INSERT);
$conn->close();
}
//INSERT INTO `food_order` (`no`, `food_name`, `food_qty`) VALUES ('1', 'Chicken Chop', '3');
?>
CASHIER.js
//var cc_price = parseFloat(document.frmCashier.cc_price.value);
//var fnc_price = 3.50;
//var tn_price = 1.50;
//var sub = 0.0;
function init() {
var customer = prompt("Please enter the customer's name");
while (customer == ""){
customer = prompt("Please enter the customer's name");}
document.getElementById('username').innerHTML = "Welcome " + customer + " to<br/>" + "Secret recipe";
document.frmCashier.cc_qty.focus();
document.frmCashier.cc_qty.value = "";
document.frmCashier.fnc_qty.value = "";
document.frmCashier.tn_qty.value = "";
document.frmCashier.cc_sub_total.value = 0;
document.frmCashier.fnc_sub_total.value = 0;
document.frmCashier.tn_sub_total.value = 0;
total();
function isAfloat(num) {
var int_num;
int_num = num - Math.floor(num);
if (int_num != 0)
return true;
else
return false;
function cc() {
var sub, qty;
var cc_price = parseFloat(document.frmCashier.cc_price.value);
qty = parseFloat(document.frmCashier.cc_qty.value);
if (isNaN(qty) || qty < 0 || isAfloat(qty)){
document.frmCashier.cc_qty.value = "";
document.frmCashier.cc_sub_total.value = 0;
document.frmCashier.cc_qty.focus();
} else {
sub = cc_price * qty;
document.frmCashier.cc_sub_total.value = sub.toFixed(2);
total();
document.frmCashier.fnc_qty.focus();
document.frmCashier.fnc_qty.select();
}
function fnc() {
var sub, qty;
var fnc_price = parseFloat(document.frmCashier.fnc_price.value);
qty = parseFloat(document.frmCashier.fnc_qty.value);
if (isNaN(qty) || qty < 0 || isAfloat(qty)) {
document.frmCashier.fnc_qty.value = "";
document.frmCashier.fnc_sub_total.value = 0;
document.frmCashier.fnc_qty.focus();
} else {
sub = fnc_price * qty;
document.frmCashier.fnc_sub_total.value = sub.toFixed(2);
total();
document.frmCashier.tn_qty.focus();
}
function tn() {
var sub, qty;
var tn_price = parseFloat(document.frmCashier.tn_price.value);
qty = parseFloat(document.frmCashier.tn_qty.value);
if (isNaN(qty) || qty < 0 || isAfloat(qty)){
document.frmCashier.tn_qty.value = "";
document.frmCashier.tn_qty.focus();
} else {
sub =tn_price * qty;
document.frmCashier.tn_sub_total.value = sub.toFixed(2);
total();
document.frmCashier.reset.focus();
}
function total() {
var sub_cc, sub_fnc, sub_tn, grand_total;
sub_cc = parseFloat(document.frmCashier.cc_sub_total.value);
sub_fnc= parseFloat(document.frmCashier.fnc_sub_total.value);
sub_tn = parseFloat(document.frmCashier.tn_sub_total.value);
grand_total = sub_cc + sub_fnc + sub_tn;
document.frmCashier.g_total.value = "RM " + grand_total.toFixed(2);
PRINT.css
body {
font-family: courier;
background-color: #FFFFFF;
font-size: small;
input[type="text"] {
text-align:right;
background-color: #FFFFFF;
border: 0px;
padding: 5px;
.center {
text-align: center;
input[type="button"] {
display:none;
th {
border-top: 1px dashed;
STYLE.css
body {
font-size: x-large;
caption {
font-size:xx-large;
input[type="text"] {
font-size:x-large;
text-align:right;
color: red;
background-color: #FFFFFF;
border: 0px;
padding: 5px;
.center {
text-align: center;
table {
background-color: #ADD8E6;
border: thin solid #000000;