-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.php
189 lines (172 loc) · 6.77 KB
/
try.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
// Include the database connection file
include("inc/connect.inc.php");
// Function to handle form submission for inserting data
function insertData($conn) {
// Check if form is submitted
if(isset($_POST['submit_insert'])) {
// Retrieve data from form
$food_items = $_POST['food_items'];
$is_breakfast = isset($_POST['is_breakfast']) ? 'TRUE' : 'FALSE';
$is_lunch = isset($_POST['is_lunch']) ? 'TRUE' : 'FALSE';
$is_dinner = isset($_POST['is_dinner']) ? 'TRUE' : 'FALSE';
$is_veg = isset($_POST['is_veg']) ? 'TRUE' : 'FALSE';
$description = $_POST['description'];
$price = $_POST['price'];
// Insert data into sample_menu table
$insert_query = pg_query($conn, "CALL insert_menu('$food_items',$is_breakfast,$is_lunch,$is_dinner,$is_veg,'$description',$price)");
// Check if insertion was successful
if($insert_query) {
echo "<script>alert('Data inserted successfully');</script>";
} else {
echo "<script>alert('Error inserting data');</script>";
}
}
}
// Function to handle form submission for updating data
function updateData($conn) {
// Check if form is submitted
if(isset($_POST['submit_update'])) {
// Retrieve data from form
$id = $_POST['update_id'];
$price = $_POST['update_price'];
// Update price in sample_menu table based on ID
$update_query = pg_query($conn, "CALL update_menu($id,$price)");
// Check if update was successful
if($update_query) {
echo "<script>alert('Price updated successfully');</script>";
} else {
echo "<script>alert('Error updating price');</script>";
}
}
}
// Function to handle form submission for deleteing data
function deleteData($conn) {
// Check if form is submitted
if(isset($_POST['submit_delete'])) {
// Retrieve data from form
$id = $_POST['delete_id'];
$delete_query = pg_query($conn, "CALL delete_menu($id)");
// Check if delete was successful
if($delete_query) {
echo "<script>alert('Record deleted successfully');</script>";
} else {
echo "<script>alert('Error delete record');</script>";
}
}
}
// Call insertData function
insertData($conn);
// Call updateData function
updateData($conn);
// Call deleteData function
deleteData($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Restaurant Database - Insert & Update</title>
<link href="img/restaurant/favicon.ico" rel="icon">
<style>
/* Styles for the form */
form {
margin-bottom: 20px;
}
form input[type="text"], form input[type="number"], form input[type="url"] {
margin-bottom: 10px;
width: 100%;
padding: 8px;
}
form input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
cursor: pointer;
}
/* Styles for tables */
table {
border-collapse: collapse;
width: 100%;
margin-bottom: 20px;
}
th, td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<div>
<button type="submit" onclick="location.href='test.php'">View Table</button>
<button class="btn btn-primary" type="button" onclick="location.href='index.php'">Back to Home</button>
<!-- <a href="test.php" type="button">View Table</a> -->
</div>
<div class="container">
<!-- Insert Form -->
<h2>Add New Menu Item</h2>
<form method="post">
<input type="text" name="food_items" placeholder="Food Items" required><br>
<input type="checkbox" name="is_breakfast"> Is Breakfast<br>
<input type="checkbox" name="is_lunch"> Is Lunch<br>
<input type="checkbox" name="is_dinner"> Is Dinner<br>
<input type="checkbox" name="is_veg"> Is Veg<br>
<input type="text" name="description" placeholder="Description" required><br>
<input type="number" name="price" placeholder="Price" required><br>
<input type="submit" name="submit_insert" value="Insert">
</form>
<!-- Update Form -->
<h2>Update Menu Item Price</h2>
<form method="post">
<input type="number" name="update_id" placeholder="ID to Update" required><br>
<input type="number" name="update_price" placeholder="New Price" required><br>
<input type="submit" name="submit_update" value="Update">
</form>
<!-- Delete Form -->
<h2>Delete Menu Item</h2>
<form method="post">
<input type="number" name="delete_id" placeholder="ID to Delete" required><br>
<input type="submit" name="submit_delete" value="Delete">
</form>
<!-- Sample Menu Table -->
<h2>Sample Menu</h2>
<table>
<tr>
<th>ID</th>
<th>Food Items</th>
<th>Is Breakfast</th>
<th>Is Lunch</th>
<th>Is Dinner</th>
<th>Is Veg</th>
<th>Description</th>
<th>Price</th>
<th>Picture</th>
</tr>
<?php
// Fetch data from sample_menu table
$menu_query = pg_query($conn, "SELECT * FROM sample_menu ORDER BY id ASC");
while ($row = pg_fetch_assoc($menu_query)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['food_items']; ?></td>
<td><?php echo $row['is_breakfast'] ? 'Yes' : 'No'; ?></td>
<td><?php echo $row['is_lunch'] ? 'Yes' : 'No'; ?></td>
<td><?php echo $row['is_dinner'] ? 'Yes' : 'No'; ?></td>
<td><?php echo $row['is_veg'] ? 'Yes' : 'No'; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['price']; ?></td>
<td><img src="<?php echo $row['picture']; ?>" alt="Menu Item" width="50" height="50"></td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
<?php pg_close($conn); ?>