<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Report a bug.</title>
    <link href='https://fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <form action="main.php" method="post">
        <h1 class="text">Report a bug.</h1>

        <label class="text" for="email">Email:</label>
        <input type="email" id="email" name="email" required>

        <label class="text" for="description">Bug Description:</label>
        <textarea id="description" name="description" rows="5" required></textarea>

        <button class="button" type="submit">Submit</button>
        <?php
            if (isset($_POST['email']) && isset($_POST['description'])) {

                $email = trim(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL));
                $bug = trim($_POST['description']);

                $pdo = new PDO(
                    'mysql:host=localhost;dbname=marcel;charset=utf8mb4',
                    'marcel',
                    'id5chuVu'
                );

                $send = $pdo->prepare(
                    "INSERT INTO bugReports (ID, email, bug)
                    VALUES (NOW(), :email, :bug)"
                );

                $send->execute([
                    ':email' => $email,
                    ':bug' => $bug
                ]);

                echo "<p>Dziękujemy, zgłoszenie zostało wysłane.</p>";
            }
        ?>
    </form>
</body>
</html>