Throwing 'Call to a member function prepare() on a non-object' on the $mysqli->prepare. The original worked perfectly fine. Is this not possible in mysqli?
Guess I should have made it clear that mysqli is set correctly as in include - $mysqli = new mysqli($db_host, $db_user, $db_pass, $db_database);
original :
mysql_query("UPDATE test_users SET lastIP=currIP, dtLastLogin=dtCurrLogin WHERE user='".$user."'");
new mysqli version:
function user_login($user)
{
// Update user's last ip and last login date in db
$stmt = $mysqli->prepare("UPDATE test_users SET lastIP = currIP, dtLastLogin = dtCurrLogin WHERE user= ?");
// bind params
$stmt->bind_param('s', $user);
// execute prepared statement
$stmt->execute();
// close statement
$stmt->close();
You can do what you want to do with mysqli
, but you haven't initialised the variable $mysqli
in your function.
Either declare it as a global
variable, or pass it in as an argument.