Repository navigation
Expand file tree
/
Copy pathadmin.php
More file actions
43 lines (37 loc) · 1.46 KB
/
Copy pathadmin.php
File metadata and controls
43 lines (37 loc) · 1.46 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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["register"])) {
// Retrieve form data
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$category = $_POST["category"];
// Validate inputs (you can add more specific validation if needed)
if (empty($username) || empty($email) || empty($password) || empty($category)) {
echo "<script>alert('All fields are required.');</script>";
} else {
// Database connection details
$servername = "localhost";
$db_username = "root";
$db_password = "";
$dbname = "accommodationfinder";
// Create connection
$conn = new mysqli($servername, $db_username, $db_password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare SQL statement to prevent SQL injection
$sql = $conn->prepare("INSERT INTO " . $category . " (username, email, password) VALUES (?, ?, ?)");
$sql->bind_param("sss", $username, $email, $password);
// Execute SQL statement
if ($sql->execute()) {
$message = "New user registered successfully.";
echo "<script>alert('$message'); window.location.href = 'admin.html';</script>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close connection
$conn->close();
}
}
?>