-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_user.php
More file actions
61 lines (54 loc) · 1.8 KB
/
Copy pathadd_user.php
File metadata and controls
61 lines (54 loc) · 1.8 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
<?php
session_start();
if (!isset($_SESSION["email"]) || $_SESSION["user_type"] != "admin") {
header("Location: login.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST["email"];
$password = $_POST["password"];
// Database connection
$conn = new mysqli("localhost", "root", "", "dbms");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert user into the database
$sql = "INSERT INTO user (email, pass) VALUES ('$email', '$password')";
if ($conn->query($sql) === true) {
echo "New user added successfully.";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Add User</title>
</head>
<body>
<div class="sidebar">
<h2 class="menu" style="color:#3BABF6">ADMIN MENU</h2>
<a href="admin_dashboard.php">Admin Dashboard</a>
<a href="user.php">Manage Users</a>
<a href="books_admin.php">Manage Books</a>
<a href="admin_cart.php">View Cart</a>
<a href="orders.php">View Orders</a>
<form method="POST" action="admin_dashboard.php">
<button type="submit" name="signout" class="button signout">Sign Out</button>
</form>
</div>
<h1>Add New User</h1>
<div class="container">
<form method="POST" action="add_user.php">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit" class="button">Add User</button>
</form>
</div>
</body>
</html>