-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
204 lines (166 loc) · 6.49 KB
/
signup.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up</title>
<link rel="shortcut icon" href="img/car10.png" type="image/x-icon">
<!-- LInk To CSS -->
<link rel="stylesheet" href="style.css">
<!-- Box Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css">
<script type="text/javascript">
function validateForm() {
var name = document.forms["signupForm"]["name"].value;
var email = document.forms["signupForm"]["email"].value;
var phone = document.forms["signupForm"]["phone"].value;
var password = document.forms["signupForm"]["password"].value;
function isValidEmail(email) {
var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z.-]+\.[a-zA-Z]{2,4}$/;
return pattern.test(email);
}
function isValidPhoneNumber(phone) {
var pattern = /^\d{10}$/; // Assumes a 10-digit phone number
return pattern.test(phone);
}
function isValidName(name) {
var pattern = /^[a-zA-Z ]+$/; // Only letters and spaces
return pattern.test(name);
}
if (name === "") {
alert("Name field is required");
return false;
} else if (!isValidName(name)) {
alert("Invalid name. Please enter valid name.");
return false;
}
if (phone === "") {
alert("Phone is required");
return false;
} else if (!isValidPhoneNumber(phone)) {
alert("Invalid phone number format. Please enter 10 digits.");
return false;
}
if (email === "") {
alert("Email is required");
return false;
} else if (!isValidEmail(email)) {
alert("Invalid email format");
return false;
}
if (password === "") {
alert("Password is required");
return false;
} else if (password.length < 8) {
alert("Password must be at least 8 characters long");
return false;
}
return true; // Form is valid
}
</script>
</head>
<body>
<!-- Navbar -->
<header>
<div class="nav container">
<!-- Logo -->
<a href="index.php" class="logo"><i class='bx bx-home'></i>SK Car Rental</a>
<!-- Log In Button -->
<a href="login.php" class="btn">Log In</a>
</div>
</header>
<!-- Sign Up -->
<div class="login container">
<div class="login-container">
<h2>Welcome , Let's get started</h2>
<!-- Signup Form -->
<form method="POST" onsubmit="return validateForm()" name="signupForm">
<span>Full Name</span>
<input type="text" name="name" id="name" placeholder="Your Name" required>
<span>Enter your email address</span>
<input type="email" name="email" id="email" placeholder="[email protected]" required>
<span>Phone</span>
<input type="tel" name="phone" id="phone" placeholder="Enter your phone number" required>
<span>Enter your password</span>
<input type="password" name="password" id="password" placeholder="At least 8" required>
<input type="submit" name="submit" value="Sign Up" class="buttom">
<a href="login.php">Already have an account?</a>
</form>
</div>
<!-- Log In Image -->
<div class="login-image">
<img src="img/car10.png" alt="">
</div>
</div>
<!-- Footer -->
<section class="footer">
<div class="footer-container container">
<img src="img/logoo.png" alt="">
<div class="footer-box">
<h3>Quick Links</h3>
<a href="index.php">Home</a>
<a href="about.php">About Us</a>
<a href="services.php">Our Services</a>
<a href="admin.php">Admin Login</a>
</div>
<div class="footer-box">
<h3>Locations</h3>
<a href="#">Nawalpur</a>
<a href="#">Chitwan</a>
<a href="#">Kathmandu</a>
</div>
<div class="footer-box">
<h3>Contact</h3>
<a href="#">+977 9812211443</a>
<a href="#">[email protected]</a>
<div class="social">
<a href="https://www.facebook.com/sohanmessi10"><i class='bx bxl-facebook'></i></a>
<a href="https://twitter.com/SohanKafle"><i class='bx bxl-twitter'></i></a>
<a href="https://www.instagram.com/sohan_lm10/"><i class='bx bxl-instagram'></i></a>
</div>
</div>
</div>
</section>
<!-- Copyright -->
<div class="copyright">
<p>© All Right Reserved SKCARRENTAL</p>
</div>
</body>
</html>
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "myproject";
$con=mysqli_connect($server,$username,$password,$database);
if(!$con){
die("Connection Failed:" . mysqli_connect_error());
}
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$password = $_POST['password'];
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Use prepared statement to prevent SQL injection
$stmt = mysqli_prepare($con, "INSERT INTO signup (name, email, phone, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $phone, $hashedPassword);
if (mysqli_stmt_execute($stmt)) {
// Admin's email address
$to = "[email protected]";
// Email subject
$subject = 'New Account Creation';
// Email content
$message = "Hello Admin, $name". "has successfully created an account in SK CAR RENTAL.";
// Email headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: [email protected]" . "\r\n";
// Send the email
if (mail($to, $subject, $message, $headers)) {
header("location: login.php");
} else {
echo'Failed to send email.';
}
}
?>