Viewing file: why_us.php (4.97 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!DOCTYPE html> <html lang="en">
<?php include 'head.php';?>
<body>
<!-- ======= Header ======= --> <?php include 'menubar.php';?>
<?php include 'sidebar.php';?>
<main id="main" class="main">
<div class="pagetitle"> <h1>Dashboard</h1> <nav> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="index.html">Home</a></li> <li class="breadcrumb-item active">Dashboard</li> </ol> </nav> </div><!-- End Page Title --> <?php include 'admin/connect.php'; ?>
<?php include 'connect.php'; // database connection
// Add Record if (isset($_POST['add'])) { $title = $_POST['title']; $desc = $_POST['description']; $link = $_POST['link']; $image = $_FILES['image']['name'];
if ($image != '') { move_uploaded_file($_FILES['image']['tmp_name'], 'images/' . $image); $sql = "INSERT INTO why_itce (title, description, link, image) VALUES ('$title', '$desc', '$link', '$image')"; $conn->query($sql); } }
// Update Record if (isset($_POST['update'])) { $id = $_POST['id']; $title = $_POST['title']; $desc = $_POST['description']; $link = $_POST['link']; $oldImage = $_POST['old_image'];
if ($_FILES['image']['name'] != '') { $image = $_FILES['image']['name']; move_uploaded_file($_FILES['image']['tmp_name'], 'images/' . $image); } else { $image = $oldImage; }
$sql = "UPDATE why_itce SET title='$title', description='$desc', link='$link', image='$image' WHERE id=$id"; $conn->query($sql); header("Location: manage_why_itce.php"); exit; }
// Delete Record if (isset($_GET['delete'])) { $id = $_GET['delete']; $conn->query("DELETE FROM why_itce WHERE id=$id"); }
// Edit Mode $editData = null; if (isset($_GET['edit'])) { $id = $_GET['edit']; $result = $conn->query("SELECT * FROM why_itce WHERE id=$id"); $editData = $result->fetch_assoc(); } ?>
<!DOCTYPE html> <html> <head> <title>Manage Why ITCE Records</title> <style> body { font-family: sans-serif; padding: 20px; background: #f7f9fc; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } th, td { padding: 10px; border: 1px solid #ccc; background: #fff; } th { background: #e9ecef; } a { padding: 4px 10px; background: #007bff; color: white; text-decoration: none; border-radius: 3px; } a.delete { background: #dc3545; } form { margin-top: 20px; background: #fff; padding: 20px; border-radius: 5px; } input[type="text"], textarea { width: 100%; padding: 8px; margin: 5px 0 10px; border: 1px solid #ccc; border-radius: 4px; } input[type="file"] { margin-bottom: 10px; } img { height: 60px; width: auto; } .btn { background: #28a745; color: white; padding: 8px 16px; border: none; border-radius: 3px; cursor: pointer; } .btn:hover { background: #218838; } </style> </head> <body>
<h2><?= $editData ? 'Edit' : 'Add New' ?> Why ITCE Record</h2> <form method="POST" enctype="multipart/form-data"> <?php if ($editData): ?> <input type="hidden" name="id" value="<?= $editData['id'] ?>"> <input type="hidden" name="old_image" value="<?= $editData['image'] ?>"> <?php endif; ?> <label>Title</label> <input type="text" name="title" value="<?= $editData['title'] ?? '' ?>" required> <label>Description</label> <textarea name="description" required><?= $editData['description'] ?? '' ?></textarea> <label>Link</label> <input type="text" name="link" value="<?= $editData['link'] ?? '' ?>"> <label>Image <?= $editData ? "(leave empty to keep old)" : "" ?></label> <input type="file" name="image"> <?php if ($editData && $editData['image']): ?> <br><img src="images/<?= $editData['image'] ?>" height="50"><br> <?php endif; ?> <br> <button type="submit" class="btn" name="<?= $editData ? 'update' : 'add' ?>"> <?= $editData ? 'Update' : 'Add' ?> </button> </form>
<h2>All Why ITCE Records</h2> <table> <tr> <th>ID</th> <th>Image</th> <th>Title</th> <th>Description</th> <th>Link</th> <th>Action</th> </tr> <?php $result = $conn->query("SELECT * FROM why_itce ORDER BY id ASC"); while ($row = $result->fetch_assoc()): ?> <tr> <td><?= $row['id'] ?></td> <td><img src="images/<?= htmlspecialchars($row['image']) ?>"></td> <td><?= htmlspecialchars($row['title']) ?></td> <td><?= htmlspecialchars($row['description']) ?></td> <td><a href="<?= htmlspecialchars($row['link']) ?>" target="_blank">Visit</a></td> <td> <a href="?edit=<?= $row['id'] ?>">Edit</a> <a href="?delete=<?= $row['id'] ?>" class="delete" onclick="return confirm('Are you sure to delete?')">Delete</a> </td> </tr> <?php endwhile; ?> </table>
</body> </html>
</main><!-- End #main -->
<?php include 'footer.php';?>
</body>
</html>
|