Database conn, users in progress

This commit is contained in:
Dr3amFury
2025-07-17 01:05:46 +02:00
parent d274fa033b
commit ef76dc973a
9 changed files with 149 additions and 8 deletions

36
register.php Normal file
View 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>