-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
90 lines (77 loc) · 3 KB
/
signup.php
File metadata and controls
90 lines (77 loc) · 3 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
session_start();
require_once 'config/database.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$database = new Database();
$db = $database->getConnection();
$name = $_POST['name'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$role = $_POST['role'];
// Check if email already exists
$check_query = "SELECT * FROM Users WHERE Email = :email";
$check_stmt = $db->prepare($check_query);
$check_stmt->bindParam(":email", $email);
$check_stmt->execute();
if ($check_stmt->rowCount() > 0) {
$error = "Email already exists";
} else {
$query = "INSERT INTO Users (Name, Email, Password, Role) VALUES (:name, :email, :password, :role)";
$stmt = $db->prepare($query);
$stmt->bindParam(":name", $name);
$stmt->bindParam(":email", $email);
$stmt->bindParam(":password", $password);
$stmt->bindParam(":role", $role);
if ($stmt->execute()) {
$_SESSION['success'] = "Registration successful! Please login.";
header("Location: login.php");
exit();
} else {
$error = "Registration failed. Please try again.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up - Real Estate Portal</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container">
<div class="auth-form">
<h2>Sign Up</h2>
<?php if (isset($error)): ?>
<div class="error"><?php echo $error; ?></div>
<?php endif; ?>
<form method="POST" action="">
<div class="form-group">
<label for="name">Full Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="role">Role:</label>
<select id="role" name="role" required>
<option value="Agent">Agent</option>
<option value="Admin">Admin</option>
</select>
</div>
<button type="submit" class="btn">Sign Up</button>
</form>
<p>Already have an account? <a href="login.php">Login</a></p>
<p><a href="index.php">Back to Home</a></p>
</div>
</div>
</body>
</html>