I am trying to perform a query which will select questions with question_id values not in the array. I saw that you are supposed to use implode
to convert the array into a string, but despite me using it I am still getting an error when doing the query.
Notice: Array to string conversion in C:\xampp\htdocs\Project\test.php on line 4
<?php
require_once 'includes/config.php';
$used = implode(',',array(0, 1, 2, 3, 4, 5, 6));
$sql = "SELECT * FROM questions WHERE module_id = ? AND (question_id NOT IN ('$used') ORDER BY RAND()";
$stmt = mysqli_prepare($connect, $sql);
mysqli_stmt_bind_param($stmt, "i", $_SESSION['module_id']);
mysqli_stmt_execute($stmt);
?>
<form method="POST" action="test.php">
<button type="submit" name="submit">Submit</button>
</form>
EDIT: Moving the implode function into a seperate variable solved the sql query, however I am now getting these errors:
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in C:\xampp\htdocs\Project\testy.php on line 8
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in C:\xampp\htdocs\Project\testy.php on line 9
Looking at the prepared statement, I cant see where it would go wrong?