Create Your Account
prepare("SELECT id FROM users WHERE email = ?"); $stmt->execute([$email]); if ($stmt->fetch()) { $error = 'A user with this email already exists.'; } else { // Hash password $hashed_password = password_hash($password, PASSWORD_DEFAULT); // Insert user $stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); if ($stmt->execute([$username, $email, $hashed_password])) { // Redirect to login page with a success message header("Location: login.php?registered=success"); exit(); } else { $error = 'Something went wrong. Please try again later.'; } } } catch (PDOException $e) { // In a real app, you would log this error. $error = 'Database error. Please try again later.'; // error_log($e->getMessage()); } } } ?>Already have an account? Login here