I am trying to access MySQL via PHP but I get these error messages.
Notice: Undefined variable: stmt in /var/www/contact.php on line 60
Fatal error: Call to a member function bind_param() on a non-object in /var/www/contact.php on line 63
My code:
<?php
$servername = "localhost";
$username = "test";
$password = "test";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// LINE 60
if(!$stmt = $conn->prepare("INSERT INTO MyGuests VALUES(?, ?, ?)") || !is_object($stmt)){
die( "Error preparing: (" .$conn->errno . ") " . $conn->error);
}
//LINE 63
$stmt->bind_param("sss", $firstname, $lastname, $email) ;