-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
106 lines (96 loc) · 4.16 KB
/
index.php
File metadata and controls
106 lines (96 loc) · 4.16 KB
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
<!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>PHP - MYSQL - CRUD</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
crossorigin="anonymous"></script>
</head>
<body>
<section>
<h1 style="text-align: center;margin: 50px 0;">PHP CRUD operations with MySQL</h1>
<div class="container">
<form action="adddata.php" method="post">
<div class="row">
<div class="form-group col-lg-4">
<label for="">Student Name</label>
<input type="text" name="name" id="name" class="form-control" required>
</div>
<div class="form-group col-lg-3">
<label for="">Grade</label>
<select name="grade" id="grade" class="form-control" required>
<option value="">Select a Grade</option>
<option value="grade6">Grade 6</option>
<option value="grade7">Grade 7</option>
<option value="grade8">Grade 8</option>
<option value="grade9">Grade 9</option>
<option value="grade10">Grade 10</option>
</select>
</div>
<div class="form-group col-lg-3">
<label for="">Marks</label>
<input type="number" name="marks" id="marks" class="form-control" required>
</div>
<div class="form-group col-lg-2" style="display: grid;align-items: flex-end;">
<input type="submit" name="submit" id="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</section>
<section style="margin: 50px 0;">
<div class="container">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Student Name</th>
<th scope="col">Grade</th>
<th scope="col">Marks</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
<?php
global $conn;
require_once "conn.php";
$sql_query = "SELECT * FROM results";
try {
// Prepare and execute the query
$stmt = $conn->prepare($sql_query);
$stmt->execute();
// Fetch results as an associative array
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$Id = $row['id'];
$Name = $row['name'];
$Grade = $row['class'];
$Marks = $row['marks'];
?>
<tr class="trow">
<td><?php echo htmlspecialchars($Id); ?></td>
<td><?php echo htmlspecialchars($Name); ?></td>
<td><?php echo htmlspecialchars($Grade); ?></td>
<td><?php echo htmlspecialchars($Marks); ?></td>
<td><a href="updatedata.php?id=<?php echo htmlspecialchars($Id); ?>" class="btn btn-primary">Edit</a></td>
<td><a href="delete.php?id=<?php echo htmlspecialchars($Id); ?>" class="btn btn-danger">Delete</a></td>
</tr>
<?php
}
} catch (PDOException $e) {
echo "Error: " . htmlspecialchars($e->getMessage());
}
?>
</tbody>
</table>
</div>
</section>
</body>
</html>