Repository navigation
Expand file tree
/
Copy pathadmin_edit.php
More file actions
62 lines (54 loc) · 2.15 KB
/
Copy pathadmin_edit.php
File metadata and controls
62 lines (54 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once 'includes/session_config.php';
include 'conn.php';
// Check if user is logged in as admin
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true || $_SESSION['user_type'] !== 'admin') {
header("Location: adminlogin.php");
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check which form was submitted based on the presence of specific fields
if (isset($_POST['user_id'])) {
// User update form was submitted
$user_id = $_POST['user_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$user_type = $_POST['user_type'];
// Update user in database
$update_sql = "UPDATE users SET name = ?, email = ?, user_type = ? WHERE user_id = ?";
$update_stmt = $conn->prepare($update_sql);
$update_stmt->bind_param("sssi", $name, $email, $user_type, $user_id);
if ($update_stmt->execute()) {
// Success
$_SESSION['message'] = "User updated successfully";
} else {
// Error
$_SESSION['error'] = "Error updating user: " . $conn->error;
}
// Redirect back to admin report page
header("Location: admin_report.php?view=users");
exit();
}
elseif (isset($_POST['project_id'])) {
// Project update form was submitted
$project_id = $_POST['project_id'];
$title = $_POST['title'];
$budget = $_POST['budget'];
$status = $_POST['status'];
// Update project in database
$update_sql = "UPDATE projects SET title = ?, budget = ?, status = ? WHERE id = ?";
$update_stmt = $conn->prepare($update_sql);
$update_stmt->bind_param("sdsi", $title, $budget, $status, $project_id);
if ($update_stmt->execute()) {
// Success
$_SESSION['message'] = "Project updated successfully";
} else {
// Error
$_SESSION['error'] = "Error updating project: " . $conn->error;
}
// Redirect back to admin report page
header("Location: admin_report.php?view=projects");
exit();
}
}
?>