I'm recieving the following error when trying to invoke a function:
Fatal error: Call to a member function prepare() on a non-object in /var/www/includes/functions.php on line 32
I am calling this function from another page using the following code:
if (login($email, $password, $mysql) == true) {
// Login success
header('Location: ../home.php');
} else {
// Login failed
header('Location: ../error.php?error=1');
}
Below is the code of the function:
function login($email, $password, $mysql) {
// Using prepared statements means that SQL injection is not possible.
if ($stmt = $mysql->prepare("SELECT id, password, salt //Line 32
FROM members
WHERE email = ?
LIMIT 1")) {
$stmt->bind_param('s', $email); // Bind "$email" to parameter.
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
I have looked at anwsers on other questions, from reading these I believe the $mysql variable is the problem.
I have tried adding the following code at the top of my functions.php but I am still getting the same result:
global $mysql
On my functions.php page I also have the following line of code:
include ("db_connect.php");
db_connect.php contains the following:
<?php
include_once 'db_config.php'; // Database information
$mysql = mysql_connect(HOST, USER, PASSWORD, DATABASE);
?>