document.getElementById("signupForm").addEventListener("submit", async (event) => {
    event.preventDefault(); // Prevent the default form submission behavior

    const name = document.getElementById("name").value;
    const email = document.getElementById("email").value;
    const password = document.getElementById("password").value;

    // Send the data to the PHP API endpoint
    try {
        const response = await fetch("php/signup.php", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({ name, email, password }),
        });

        const result = await response.json();
        if (response.ok) {
            alert(result.message); // Show success message
            window.location.href = "landing.html"; // Redirect to the landing page
        } else {
            alert(result.error); // Show error message
        }
    } catch (error) {
        console.error("Error signing up:", error);
        alert("An error occurred. Please try again.");
    }
});
