Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Index

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

<!

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">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
icons@1.10.1/font/bootstrap-icons.css">
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<title>CRUD</title>
</head>

<body style="background-image: url('bg.png'); background-size: cover; background-


repeat: no-repeat;">
<h1 class="text-center mt-5">College Department</h1>
<div class="container">
<div class="py-4">
<a href="./create.php" class="btn btn-success">
<i class="bi bi-plus-circle-fill"></i> Add Student
</a>
</div>
<table class="table table-bordered table-striped align-middle table-light">
<thead class="table-dark">
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Age</th>
<th>Course</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
require_once "./config.php";

// Update the SQL query to select from the new table and column names
$sql = "SELECT id, firstname, lastname, email, age, course FROM students";

if ($result = mysqli_query($link, $sql)) {


if (mysqli_num_rows($result) > 0) {
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$count = 1;
foreach ($rows as $row) { ?>
<tr>
<td><?= $count++; ?></td>
<td><?= htmlspecialchars($row["firstname"]); ?></td>
<td><?= htmlspecialchars($row["lastname"]); ?></td>
<td><?= htmlspecialchars($row["email"]); ?></td>
<td><?= htmlspecialchars($row["age"]); ?></td>
<td><?= htmlspecialchars($row["course"]); ?></td>
<td>
<a href="./update.php?id=<?= $row["id"]; ?>" class="btn btn-
primary btn-sm">
<i class="bi bi-pencil-square"></i>
</a>&nbsp;
<a href="./delete.php?id=<?= $row["id"]; ?>" class="btn btn-
danger btn-sm">
<i class="bi bi-trash-fill"></i>
</a>
</td>
</tr>
<?php
}
mysqli_free_result($result);
} else { ?>
<tr>
<td class="text-center text-danger fw-bold" colspan="7">** No records
were found **</td>
</tr>
<?php
}
}
mysqli_close($link);
?>
</tbody>
</table>
</div>

<script>
const delBtnEl = document.querySelectorAll(".btn-danger");
delBtnEl.forEach(function(delBtn) {
delBtn.addEventListener("click", function(e) {
const message = confirm("Are you sure you want to delete this record?");
if (!message) {
e.preventDefault();
}
});
});
</script>
</body>

</html>

You might also like