-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstudent_signup.php
More file actions
30 lines (24 loc) · 896 Bytes
/
student_signup.php
File metadata and controls
30 lines (24 loc) · 896 Bytes
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "frontend&backend";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$username = trim($_POST['username']);
$email = trim($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$stmt = $conn->prepare("INSERT INTO students (username, email, password) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $username, $email, $password);
if ($stmt->execute()) {
echo "<script>alert('Registration successful!'); window.location.href='student_login.html';</script>";
} else {
echo "<script>alert('Error: " . $conn->error . "'); window.history.back();</script>";
}
$stmt->close();
}
$conn->close();
?>