I have an SQL statement in PHP as follows:
$sql = "SELECT t_da_edu_questions.ID, t_da_edu_questions.question_part1, t_da_edu_questions.question_part2, t_da_edu_questions.question_part3, t_da_edu_questions.answer, t_da_edu_questions.option2, t_da_edu_questions.option3, t_da_edu_questions.option4, t_da_edu_questions.option5, t_da_edu_questions.Supplerende, t_da_edu_questions.pic_id, t_da_edu_questions.Category_ID, t_da_edu_questions.approved, t_da_edu_questions.NeedAdmin
FROM t_da_edu_questions
WHERE (((t_da_edu_questions.Category_ID=?)) AND ((t_da_edu_questions.approved)=1) AND ((t_da_edu_questions.NeedAdmin)=0) AND
((t_da_edu_questions.ID) Not In (SELECT t_da_edu_UserAnswers.ID_qst FROM t_da_edu_UserAnswers WHERE ((t_da_edu_UserAnswers.ID_team = ?) AND T_da_edu_UserAnswers.AnsOrBack = 1 ))))
ORDER BY RAND()
LIMIT 1";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "ii", $cat, $TeamID); //(Line 36 in error)
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
I get the error:
Fatal error: Uncaught Error: mysqli_stmt object is not fully initialized in C:\xampp\htdocs\app\content\db.php:36 Stack trace: #0 C:\xampp\htdocs\app\content\db.php(36): mysqli_stmt_bind_param(Object(mysqli_stmt), 'ii', '6', 304) #1
If I remove the subquery in "Not In" it works fine. I have not been able to find a similar problem.
So, basically, how do i properly add prepared statement to query with sub query?