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...