-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.php
More file actions
38 lines (33 loc) · 1.23 KB
/
registration.php
File metadata and controls
38 lines (33 loc) · 1.23 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
// registration.php
<?php
require_once 'config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$role = "customer"; // Default role for new registrations
// Check if email exists
$check = "SELECT * FROM users WHERE email='$email'";
$result = mysqli_query($conn, $check);
if (mysqli_num_rows($result) > 0) {
echo "<script>
alert('Email already registered!');
window.location.href = 'home-page.html';
</script>";
} else {
$sql = "INSERT INTO users (name, email, password, role)
VALUES ('$name', '$email', '$password', '$role')";
if (mysqli_query($conn, $sql)) {
echo "<script>
alert('Registration successful! Please login.');
window.location.href = 'Login-Sign-Up.html';
</script>";
} else {
echo "<script>
alert('Registration failed! Please try again.');
window.location.href = 'Login-Sign-Up.html';
</script>";
}
}
}
?>