Please friends help me. I can't find out where am going wrong. All the variables I need to update are so far good, but the actual update statement returns an error saying
"Uncaught Error: Call to a member function prepare() on null"
Below is a small piece of my php code:
$name_image=basename($_FILES[$idx]["name"]["$key"]);
$time = date("Y-m-d H:i:s");
$email_insert = $_SESSION['email'];
$sql_upl ="UPDATE forepost_users SET profile_picture ='$name_image',lastmodified ='$time' WHERE email_address=?";
$SQL_statement_upl= $this->conn->prepare($sql_upl);
$SQL_statement_upl->bindParam(1,$email_insert);
$SQL_statement_upl->execute();
There are at least two problems.
$conn
isn't initialized which is why you're getting this error because $conn
is null and you're attempting to call a member function of a null object.Please include your $conn
initialization code if you need assistance resolving issues with that.
SET profile_picture ='$name_image',lastmodified ='$time'
This part of your UPDATE
statement will not insert the values of $name_image
and $time
into the SQL statement. Remember this is a 'prepared statement', so you're creating a SQL template that will be executed multiple times. Each time it is executed, you're passing the values into the SQL statement through the bound parameters.
So change your prepared statement to:
"UPDATE forepost_users SET profile_picture = ?, lastmodified = ? WHERE email_address = ?"
Then bind each of the parameters before execution:
$SQL_statement_upl->bindParam(1,$name_image);
$SQL_statement_upl->bindParam(2,$time);
$SQL_statement_upl->bindParam(3,$_email_insert);