<?php
$insert = false;

if (isset($_POST['name'])) {
    $server = "localhost";
    $username = "root";
    $password = "";

    $con = mysqli_connect($server, $username, $password);

    if (!$con) {
        die("Connection to this database failed due to " . mysqli_connect_error());
    }

    // echo "success connecting to the db";

    $name = $_POST['name'];
    $gender = $_POST['gender'];
    $age = $_POST['age'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $desc = $_POST['desc'];

    $sql = "INSERT INTO `trip`. `trip` (`name`, `age`, `gender`, `email`, `phone`, `desc`, `dt`) VALUES ('$name', '$age', '$gender', '$email', '$phone', '$desc', current_timestamp());";

    // echo $sql;

    if ($con->query($sql) === true) {
        // echo "successfully inserted";
        $insert = true;
    } else {
        echo "Error: $sql <br> $con->error";
    }

    $con->close();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Travel Us Trip</title>

    <link rel="preconnect" href="https://f...content-available-to-author-only...s.com">
    <link rel="preconnect" href="https://f...content-available-to-author-only...c.com" crossorigin>
    <link href="https://f...content-available-to-author-only...s.com/css2?family=Rubik+Wet+Paint&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <img class="bg" src="bg.png" alt="iiit">
    <div class="container">
        <h1>Travel for Us Trip Form</h1>
        <p>Hi, we are ready to go to the US!</p>

        <?php
        if ($insert == true) {
            echo "<p class='submitmsg'>Thanks for submitting your form. We are happy to see you.</p>";
        }
        ?>

        <form action="index.php" method="post">
            <input type="text" name="name" id="name" placeholder="Enter your name">
            <input type="text" name="age" id="age" placeholder="Enter your age">
            <input type="email" name="email" id="email" placeholder="Enter your email">
            <input type="phone" name="phone" id="phone" placeholder="Enter your phone">
            <textarea name="desc" id="desc" cols="30" rows="10" placeholder="Enter description of your trip"></textarea>
            <button class="btn">Submit</button>
        </form>
    </div>

    <script src="index.js"></script>
</body>
</html>
