| Server IP : 127.0.0.1 / Your IP : 216.73.216.48 Web Server : Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 System : Windows NT DESKTOP-3H4FHQJ 10.0 build 19045 (Windows 10) AMD64 User : win 10 ( 0) PHP Version : 8.2.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/xampp/htdocs-coblaa/Cinevaa/ |
Upload File : |
<?php
session_start();
include('db.php');
// Security: Check if logged in
if (!isset($_SESSION['my_id'])) {
header("Location: login.php");
exit();
}
// 1. Get the Admin's current data
if (isset($_GET['id'])) {
$id = $_GET['id'];
$result = mysqli_query($con, "SELECT * FROM admins WHERE id = $id");
$row = mysqli_fetch_assoc($result);
}
// 2. Handle the Update request
if (isset($_POST['update'])) {
$id = $_POST['id'];
$username = $_POST['username'];
$email = $_POST['email'];
$role = $_POST['role'];
$sql = "UPDATE admins SET username='$username', email='$email', role='$role' WHERE id=$id";
if (mysqli_query($con, $sql)) {
header("Location: admin_temp?msg=Admin Updated Successfully");
exit();
} else {
echo "Error updating record: " . mysqli_error($con);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Edit Admin</title>
</head>
<body class="bg-light">
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow">
<div class="card-header bg-warning text-dark"><h5>Edit Admin User</h5></div>
<div class="card-body">
<form action="edit.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<div class="mb-3">
<label>Username</label>
<input type="text" name="username" class="form-control" value="<?php echo $row['username']; ?>" required>
</div>
<div class="mb-3">
<label>Email</label>
<input type="email" name="email" class="form-control" value="<?php echo $row['email']; ?>" required>
</div>
<div class="mb-3">
<label>Role</label>
<select name="role" class="form-select">
<option value="admin" <?php if($row['role'] == 'admin') echo 'selected'; ?>>Admin</option>
<option value="editor" <?php if($row['role'] == 'editor') echo 'selected'; ?>>Editor</option>
</select>
</div>
<button type="submit" name="update" class="btn btn-warning w-100">Update Admin</button>
<a href="index.php" class="btn btn-link w-100 mt-2">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>