So I've got problem with my PHP code where I'm trying to run two prepared statements which have been 'prepare'd with the same $mysqli object.
require 'database.php';
$mysqli = new mysqli($database_host, $database_user, $database_pass, $database_name);
/*First check if there is already a preference record for this user
with this particular course.*/
$query = "SELECT * FROM timetablePrefs WHERE username=? AND courseID=?";
$stmt = $mysqli->prepare($query);
foreach ($courseList as $key => $value)
{
$stmt->bind_param("ss", $username, $key);
$stmt->execute();
if (($stmt->num_rows) === 1)
continue;
else
{
$query = "INSERT INTO timetablePrefs (username, courseID, hexColour, hidden) ";
$query .= "VALUES (?, ?, ?, 0)";
$prepared = $mysqli->prepare($query);
$prepared->bind_param("sss", $username, $key, "#FFFFFF");
if (!($prepared->execute()))
print("Sorry couldnt change your colour preferences.");
$prepared->close();
}
}
$stmt->close();
$mysqli->close();
I may be missing something here; can you even run two of these at the same time? Any help would be greatly appreciated!Any questions please ask ;)
The error I receive is with regards to the line;
$prepared->bind_param("sss", $username, $key, "#FFFFFF");
Fatal error: Call to a member function bind_param() on a non-object