Database conn, users in progress
This commit is contained in:
36
register.php
Normal file
36
register.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
require_once 'db.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (!$username || !$email || !$password) {
|
||||
die('All fields are required.');
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
|
||||
// Check if user exists
|
||||
$stmt = $conn->prepare("SELECT id FROM Users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetch()) {
|
||||
die('Email already registered.');
|
||||
}
|
||||
|
||||
$hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $conn->prepare("INSERT INTO Users (username, email, password) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$username, $email, $hashed]);
|
||||
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="POST">
|
||||
<input type="text" name="username" placeholder="Username" required>
|
||||
<input type="email" name="email" placeholder="Email" required>
|
||||
<input type="password" name="password" placeholder="Password" required>
|
||||
<button type="submit">Register</button>
|
||||
</form>
|
||||
Reference in New Issue
Block a user