prepare("SELECT id FROM users WHERE email = ?"); $stmt->execute([$email]); if ($stmt->fetch()) { $errors[] = 'Email already in use.'; } else { $hashed_password = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)"); if ($stmt->execute([$name, $email, $hashed_password])) { $_SESSION['success_message'] = 'Registration successful! Please login.'; header('Location: /index.php#loginModal'); exit; } else { $errors[] = 'Something went wrong. Please try again.'; } } } // To display errors, we would need to render a form here. // For now, we redirect back to the form with errors in session. $_SESSION['register_errors'] = $errors; header('Location: /index.php#signupModal'); exit; } // This script does not render HTML. It only processes the form. header('Location: /index.php'); exit;