I have researched it a lot online and spent a lot of time trying to fix this problem. My code
function createNewAccount() {
global $response;
global $conn;
// prepare and bind
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $firstname, $lastname, $email);
// set parameters and execute
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$stmt->execute();
}
the error I get is
Warning: mysqli::prepare(): Couldn't fetch mysqli in C:\xampp\htdocs\authentication\register.php on line 105
Fatal error: Uncaught Error: Call to a member function bind_param() on null in C:\xampp\htdocs\authentication\register.php:106 Stack trace: #0 C:\xampp\htdocs\authentication\register.php(139): createNewAccount() #1 {main} thrown in C:\xampp\htdocs\authentication\register.php on line 106
I cant seem to find any solution. Any help is highly appreciated.