Skip to content

Commit

Permalink
perf: maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
Faelayis committed Sep 18, 2024
1 parent 928acd8 commit fec3d91
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 85 deletions.
8 changes: 4 additions & 4 deletions COM-2305/67-09-16/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ <h3 class="text-lg font-semibold mt-4 mb-2">Test</h3>
<div class="flex-1 p-4" id="main-content">
<!-- <header class="mb-4">
<h1 class="text-2xl font-bold">Hello World</h1>
</header> -->
<!-- <main>
<p>content</p>
</main> -->
</header>
<main>
<p>content</p>
</main> -->
</div>
</div>
</body>
Expand Down
41 changes: 20 additions & 21 deletions COM-2305/67-09-16/php/faculty/add.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include("../../../Exercise/8/connected_database.php");
if (!$_SERVER["REQUEST_METHOD"] == "POST") return;
include("../../../Exercise/8/connected_database.php");

$fac_id = $_POST['id'];
$fac_name = $_POST['name'];
$faculty_id = $_POST['id'];
$faculty_name = $_POST['name'];

$sql = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)";
$stmt = mysqli_prepare($db, $sql);
mysqli_stmt_bind_param($stmt, "is", $fac_id, $fac_name);
$query = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)";
$stmt = mysqli_prepare($db, $query);

if (mysqli_stmt_execute($stmt)) {
include("../../functions/previous_page.php");
} else {
switch (mysqli_errno($db)) {
case '1062':
include("../../functions/previous_page.php");
break;
mysqli_stmt_bind_param($stmt, "is", $faculty_id, $faculty_name);

default:
echo "Error: " . $sql . "<br>" . mysqli_error($db);
break;
}
if (mysqli_stmt_execute($stmt)) {
include("../../functions/previous_page.php");
} else {
switch (mysqli_errno($db)) {
case '1062':
include("../../functions/previous_page.php");
break;
default:
echo "Error: " . $query . "<br>" . mysqli_error($db);
break;
}

mysqli_stmt_close($stmt);
mysqli_close($db);
}

mysqli_stmt_close($stmt);
mysqli_close($db);
32 changes: 15 additions & 17 deletions COM-2305/67-09-16/php/faculty/delete.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include("../../../Exercise/8/connected_database.php");
if (!$_SERVER["REQUEST_METHOD"] == "POST") return;
include("../../../Exercise/8/connected_database.php");

$fac_id = $_POST['Fac_id'];
$sql = "DELETE FROM faculty WHERE Fac_id = ?";
$faculty_id = $_POST['Fac_id'];
$query = "DELETE FROM faculty WHERE Fac_id = ?";

if ($stmt = mysqli_prepare($db, $sql)) {
mysqli_stmt_bind_param($stmt, "i", $fac_id);
if ($stmt = mysqli_prepare($db, $query)) {
mysqli_stmt_bind_param($stmt, "i", $faculty_id);

if (mysqli_stmt_execute($stmt)) {
header("Location: " . $_SERVER['HTTP_REFERER']);
exit();
} else {
echo "Error deleting record: " . mysqli_error($db);
}

mysqli_stmt_close($stmt);
if (mysqli_stmt_execute($stmt)) {
header("Location: " . $_SERVER['HTTP_REFERER']);
exit();
} else {
echo "Error preparing statement: " . mysqli_error($db);
echo "Error deleting record: " . mysqli_error($db);
}

mysqli_close($db);
} else {
echo "Error preparing statement: " . mysqli_error($db);
}

mysqli_stmt_close($stmt);
mysqli_close($db);
2 changes: 2 additions & 0 deletions COM-2305/67-09-16/php/faculty/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

$query = "SELECT Fac_id, Fac_name FROM faculty";
$result = mysqli_query($db, $query);

mysqli_close($db);
9 changes: 3 additions & 6 deletions COM-2305/67-09-16/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

document.addEventListener("DOMContentLoaded", function () {
const links = document.querySelectorAll(".sidebar-link");
const mainContent = document.getElementById("main-content");
Expand All @@ -9,16 +7,15 @@ document.addEventListener("DOMContentLoaded", function () {
}

links.forEach((link) => {
link.addEventListener("click", function (e) {
e.preventDefault();
link.addEventListener("click", function (event) {
event.preventDefault();
const url = this.getAttribute("href");

if (url === "") {
return (mainContent.innerHTML = "<p>404 Not Found</p>");
return (mainContent.innerHTML = "<p>Error 404 Not Found</p>");
}

localStorage.setItem("lastUrl", url);

loadContent(url);
});
});
Expand Down
50 changes: 26 additions & 24 deletions COM-2305/67-09-16/sidebar/faculty/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
include("../../php/faculty/get.php");
?>

<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
<table class="w-full text-sm text-left rtl:text-right text-gray-400 dark:text-gray-400">
<thead class="text-xs text-gray-400 uppercase bg-gray-700 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">
Faculty ID
</th>
<th scope="col" class="px-6 py-3">
Faculty Name
</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<tr class="bg-gray-800 dark:bg-gray-800 dark:border-gray-700">
<th scope="row" class="px-6 py-4 font-medium text-white whitespace-nowrap dark:text-white">
<?php echo htmlspecialchars($row['Fac_id']); ?>
<body>
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
<table class="w-full text-sm text-left rtl:text-right text-gray-400 dark:text-gray-400">
<thead class="text-xs text-gray-400 uppercase bg-gray-700 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" class="px-6 py-3">
Faculty Id
</th>
<th scope="col" class="px-6 py-3">
Faculty Name
</th>
<td class="px-6 py-4">
<?php echo htmlspecialchars($row['Fac_name']); ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<tr class="bg-gray-800 dark:bg-gray-800 dark:border-gray-700">
<th scope="row" class="px-6 py-4 font-medium text-white whitespace-nowrap dark:text-white">
<?php echo htmlspecialchars($row['Fac_id']); ?>
</th>
<td class="px-6 py-4">
<?php echo htmlspecialchars($row['Fac_name']); ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</body>
25 changes: 12 additions & 13 deletions COM-2305/Exercise/8/3.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php
include("./connected_database.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$fac_id = $_POST['id'];
$fac_name = $_POST['name'];
$faculty_id = $_POST['id'];
$faculty_name = $_POST['name'];

$sql = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)";
$stmt = mysqli_prepare($db, $sql);
mysqli_stmt_bind_param($stmt, "is", $fac_id, $fac_name);
$query = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)";
$stmt = mysqli_prepare($db, $query);

if (mysqli_stmt_execute($stmt)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($db);
}
mysqli_stmt_bind_param($stmt, "is", $faculty_id, $faculty_name);

mysqli_stmt_close($stmt);
mysqli_close($db);
if (mysqli_stmt_execute($stmt)) {
echo "New record created successfully";
} else {
echo "Error: " . $query . "<br>" . mysqli_error($db);
}

mysqli_stmt_close($stmt);
mysqli_close($db);

0 comments on commit fec3d91

Please sign in to comment.