数据无法在表单提交时发送? [关闭]

This is my code:

<?php
require_once "connect.php";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $email = test_input($_POST["email"]);
    if(!empty($email))
    {
        $insert = $db->prepare("INSERT INTO creations(email) VALUES (?)");
        $insert->bind_param('s', $email);
    }
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

<!DOCTYPE html>
<html>
    <body>
        <form method="post" action="">

            <input type="text" name="email">
            <input type="submit">
        </form>
    </body>
</html>

When I submit anything in the email input box, I get an error saying this:

Fatal error: Call to a member function bind_param() on a non-object in /home/xx/xx/xx/xx on line 12.

I've tried this with a few different forms and got the same error. I've double checked everything on both my database and in my PHP code...

This should do the trick let me know if you have any problems.

//CODE

<?php
//PATH --- /var/www/html/connect.php
require_once($_SERVER['DOCUMENT_ROOT'] . "/connect.php");
if (isset($_POST["email"])){
    $email = filter_data($_POST["email"]);
    $stmt = $db->prepare("INSERT INTO creations(email) VALUES (?)"); 
    $stmt->bind_param('s', $email);
    $stmt->execute();
    $stmt->close(); 
}
function filter_data($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>
<!DOCTYPE html>
<html>
    <body>
        <form method="post" action="">
            <input type="text" name="email">
            <input type="submit">
        </form>
    </body>
</html>