From e031215516573b14545e81665b991176a467bce5 Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Sat, 3 Feb 2024 16:29:27 +0000 Subject: Implement PHP assignment #3, improve the rest --- mysql-php/code/a3.php | 132 +++++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 55 deletions(-) (limited to 'mysql-php/code/a3.php') diff --git a/mysql-php/code/a3.php b/mysql-php/code/a3.php index f029dd8..65fa2b9 100644 --- a/mysql-php/code/a3.php +++ b/mysql-php/code/a3.php @@ -1,23 +1,24 @@ set_charset('utf8mb4'); + $dbh->query('CREATE DATABASE IF NOT EXISTS EATERY_DB'); + $dbh->select_db('EATERY_DB'); + $dbh->query('CREATE TABLE IF NOT EXISTS `FOOD_DETAILS` (`FOOD_ID` INT PRIMARY KEY, `FOOD_ITEM` VARCHAR(255), `PRICE_PER_ITEM` DOUBLE, UNIQUE (`FOOD_ID`))'); + $dbh->query('INSERT INTO `FOOD_DETAILS` VALUES + (1, "Egg Biriyani (w/ 2 eggs)", 200), + (2, "Chicken Biriyani", 300), + (3, "Mutton Biriyani", 350), + (4, "Veg Pulao", 200), + (5, "Shahi Paneer", 220), + (6, "Schezwan Paneer", 240), + (7, "Steam Rice", 90) + ON DUPLICATE KEY UPDATE `FOOD_ITEM` = VALUES(`FOOD_ITEM`)'); + $dbh->query('CREATE TABLE IF NOT EXISTS `CUSTOMER_DETAILS` (`BILL_ID` INT PRIMARY KEY AUTO_INCREMENT, `CUSTOMER_NAME` VARCHAR(255), `TOTAL_AMOUNT_PAID` DOUBLE, `DATE_OF_PAYMENT` DATE)'); return $dbh; } @@ -32,22 +33,14 @@ h2 { font-size: 1.8rem; font-weight: 500; } form { margin: 2em auto; width: 20em; } form > * { padding: 0.5em; } table, tr, th, td { border-collapse: collapse; border: 1px solid black; } +table.noborder, table.noborder * { border: none; } +table.invoice td:nth-child(2), table.invoice td:nth-child(3) { text-align: end; } +p.right { text-align: right; } th, td { padding: 5px; } -
-

Enter E-mail address to search for the record of a student

- - -
- @@ -57,39 +50,68 @@ function display_failure($reason) { die(); } -function search_and_show($dbh, $email) { - $stmt = mysqli_prepare($dbh, 'SELECT * FROM STUDENT WHERE EMAIL = ?'); - $result = mysqli_query($dbh, ); - html_prologue('Students\' details'); +function show_menu($dbh) { + html_prologue('Eatery Menu'); ?> -

Students' details

-

record(s) found.

- - - - - - - - - - "> +

Welcome to Delish Eatery

+
Roll No.NameE-mailCityDate of birth
- ', array_map('htmlspecialchars', [ - $row['ROLL'], $row['NAME'], $row['EMAIL'], $row['CITY'], - $row['DATE_OF_BIRTH'] - ])); ?> -
+ + + query('SELECT * FROM `FOOD_DETAILS`'); + while ($row = $result->fetch_assoc()) { + echo ''; + echo '', ''; } ?> +
ServingsFood itemPrice
', $row['FOOD_ITEM'], '₹', number_format(+$row['PRICE_PER_ITEM'], 2), '
- + query('SELECT * FROM `FOOD_DETAILS` WHERE `FOOD_ID` IN (' . implode(', ', $orders) . ')')->fetch_all(MYSQLI_ASSOC); + $total_price = 0.0; + foreach ($items as $i => $item) { + $items[$i]['price'] = $servings[$item['FOOD_ID']] * $item['PRICE_PER_ITEM']; + $total_price += $items[$i]['price']; + } + $tax = 0.15 * $total_price; + $net_price = $total_price + $tax; + $stmt = $dbh->prepare('INSERT INTO `CUSTOMER_DETAILS` (`CUSTOMER_NAME`, `TOTAL_AMOUNT_PAID`, `DATE_OF_PAYMENT`) VALUES (?, ?, ?)'); + $stmt->bind_param('sds', $_POST['customer_name'], $net_price, @date('Y-m-d')); + $stmt->execute(); + $bill_id = $dbh->insert_id; + html_prologue('Customer invoice'); + ?> +

Customer Invoice

+

Bill No.: D.E./

+

Name:

+ + +'; +} ?> + + + +
Food itemServingsPrice
', implode('', [$item['FOOD_ITEM'], $servings[$item['FOOD_ID']], number_format($item['price'], 2)]), '
Total:
GST (15%):
Net price:
+ close(); +} catch (mysqli_sql_exception $e) { + display_failure($e->getMessage()); } + -- cgit 1.4.1-2-gfad0