Viewing file: students_password.php (5.17 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!DOCTYPE html> <html lang="en">
<?php include 'head.php';?> <style> table { border-collapse: collapse; width: 100%; margin-top: 20px; }
table, th, td { border: 1px solid #ddd; }
th, td { padding: 8px; text-align: left; }
th { background-color: #f2f2f2; font-weight: bold; } .custom-image { width: 100px; height: 100px; } </style> <body>
<!-- ======= Header ======= --> <?php include 'menubar.php';?>
<?php include 'sidebar.php';?>
<main id="main" class="main">
<?php include 'connect.php';
// Add / Update student if (isset($_POST['save'])) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $username = $conn->real_escape_string($_POST['username']); $password = $conn->real_escape_string($_POST['password']); // Hash later if needed $paper_code = $conn->real_escape_string($_POST['paper_code']); $student_name = $conn->real_escape_string($_POST['student_name']);
// Check for duplicate (username + paper_code) $dupQuery = "SELECT ID FROM studentlogin WHERE username='$username' AND paper_code='$paper_code'"; if ($id > 0) { $dupQuery .= " AND ID != $id"; // ignore self while editing } $dupCheck = $conn->query($dupQuery);
if ($dupCheck->num_rows > 0) { echo "<script>alert('❌ Duplicate entry found: Username + Paper Code already exists!'); window.location='ststudents_password.php';</script>"; exit(); }
if ($id > 0) { // Update $sql = "UPDATE studentlogin SET username='$username', password='$password', paper_code='$paper_code', student_name='$student_name' WHERE ID=$id"; $conn->query($sql); } else { // Insert $sql = "INSERT INTO studentlogin (username,password,paper_code,student_name) VALUES ('$username','$password','$paper_code','$student_name')"; $conn->query($sql); } }
// Delete if (isset($_GET['delete'])) { $id = intval($_GET['delete']); $conn->query("DELETE FROM studentlogin WHERE ID=$id"); }
// Edit record fetch $editData = null; if (isset($_GET['edit'])) { $id = intval($_GET['edit']); $res = $conn->query("SELECT * FROM studentlogin WHERE ID=$id"); $editData = $res->fetch_assoc(); }
// Fetch all students $result = $conn->query("SELECT ID, username, password, paper_code, student_name FROM studentlogin ORDER BY ID DESC"); ?>
<!DOCTYPE html> <html> <head> <title>Student Login Management</title> <style> body { font-family: Arial; padding:20px; background:#f4f4f4; } h2 { text-align:center; color:#004080; } form { background:#fff; padding:15px; margin-bottom:20px; border-radius:6px; box-shadow:0 0 8px rgba(0,0,0,0.1); } label { display:block; margin-top:10px; } input[type=text], input[type=password] { width:100%; padding:8px; margin-top:5px; border:1px solid #ccc; border-radius:4px; } button { margin-top:10px; padding:8px 16px; background:#004080; color:#fff; border:none; border-radius:4px; cursor:pointer; } button:hover { background:#0066cc; } table { width:100%; border-collapse:collapse; background:#fff; box-shadow:0 0 8px rgba(0,0,0,0.05); } th,td { border:1px solid #ccc; padding:10px; text-align:center; } th { background:#004080; color:white; } a { text-decoration:none; padding:5px 10px; border-radius:4px; } .edit { background:#28a745; color:white; } .delete { background:#dc3545; color:white; } </style> </head> <body>
<h2>Student Login Management</h2>
<form method="post"> <input type="hidden" name="id" value="<?= $editData['ID'] ?? '' ?>"> <label>Username:</label> <input type="text" name="username" required value="<?= $editData['username'] ?? '' ?>"> <label>Password:</label> <input type="text" name="password" required value="<?= $editData['password'] ?? '' ?>"> <label>Paper Code:</label> <input type="text" name="paper_code" required value="<?= $editData['paper_code'] ?? '' ?>"> <label>Student Name:</label> <input type="text" name="student_name" required value="<?= $editData['student_name'] ?? '' ?>"> <button type="submit" name="save"><?= $editData ? 'Update' : 'Add' ?> Student</button> </form>
<table> <thead> <tr> <th>ID</th> <th>Username</th> <th>Password</th> <th>Paper Code</th> <th>Student Name</th> <th>Action</th> </tr> </thead> <tbody> <?php while ($row = $result->fetch_assoc()): ?> <tr> <td><?= $row['ID'] ?></td> <td><?= htmlspecialchars($row['username']) ?></td> <td><?= htmlspecialchars($row['password']) ?></td> <td><?= htmlspecialchars($row['paper_code']) ?></td> <td><?= htmlspecialchars($row['student_name']) ?></td> <td> <a class="edit" href="?edit=<?= $row['ID'] ?>">Edit</a> <a class="delete" href="?delete=<?= $row['ID'] ?>" onclick="return confirm('Delete this record?')">Delete</a> </td> </tr> <?php endwhile; ?> </tbody> </table>
</body> </html>
</main><!-- End #main -->
<?php include 'footer.php';?>
</body>
</html>
|