-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
98 lines (79 loc) · 2.53 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Student List App</title>
<link rel="stylesheet" href="./default.css" />
</head>
<body>
<h1>Student List App</h1>
<h3>For Educational Tour</h3>
<main>
<form method="POST" action="./insert.php">
<label for="name">Student Name</label>
<input type="text" id="name" name="name" required />
<label for="roll">Student ID</label>
<input type="text" id="roll" name="roll" required />
<label for="amount">Amount</label>
<input type="text" id="amount" name="amount" required value="700" />
<button class="btn btn-blue" type="submit">Add</button>
</form>
<!-- HTML Form: https://www.w3schools.com/tags/tag_form.asp -->
<?php
require_once './connectDB.php';
$table_start = '<table>
<thead>
<tr>
<th>#</th>
<th>Student Name</th>
<th>Roll</th>
<th>Amount</th>
<th></th>
</tr>
</thead>
<tbody>';
$table_end = '</tbody>
</table>
<!-- HTML Table: https://www.w3schools.com/tags/tag_table.asp -->
';
$result = $conn->query("SELECT * FROM students");
if ($result->num_rows > 0) {
// *** Bellow code (commented) should be removed ***
// $text = json_encode($result);
// echo "<script>console.log(" . $text . ");</script>";
echo $table_start;
while ($row = $result->fetch_assoc()) {
// *** Bellow code (commented) should be removed ***
// $text = json_encode($row);
// echo "<script>console.log(" . $text . ");</script>";
echo '<tr>
<td>' . $row['id'] . '</td>
<td>' . $row['name'] . '</td>
<td>' . $row['roll'] . '</td>
<td>' . $row['amount'] . '</td>
<td>
<a class="btn btn-green" href="edit.php?id=' . $row['id'] . '">Edit</a>
<a class="btn btn-red" href="delete.php?id=' . $row['id'] . '">Delete</a>
</td>
</tr>';
}
echo $table_end;
} else {
echo '<p style="text-align:center; font-weight:bold;">There is no data found to show.</p>';
}
// *** Bellow code (commented) should be removed ***
// if ($x = 0) {
// echo "<script>console.log('YES');</script>";
// } else {
// echo "<script>console.log('NO');</script>";
// }
// *** Bellow code (commented) should be removed ***
// while ($x = 1) {
// echo "<script>console.log('YES');</script>";
// }
?>
</main>
</body>
</html>