<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];

    if (userExists($username)) {
        $message = "Username already taken.";
    } else {
        saveUser($username, $password);
        $message = "Sign-up successful! <a href='login.php'>Login here</a>";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign Up</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <form method="POST" action="signup.php">
        <input type="text" name="username" placeholder="Enter username" required>
        <input type="password" name="password" placeholder="Enter password" required>
        <button type="submit">Sign Up</button>
    </form>
    <?php if(isset($message)) echo "<p>$message</p>"; ?>
    <p>Already have an account? <a href="login.php">Login here</a></p>
</body>
</html>
