This question already has an answer here:
I've looked all over the internet for answers on this one, and prepared statements and bind params come up (I have no idea what that stuff is)
Basically, I have a comma separated list
$list = 'food, drink, cooking';
Ok, now I want to search for each of those items in a column of the database... Sounds simple, right?
$query = "SELECT * FROM table WHERE stuff IN ('$list')";
$runquery = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($runquery,MYSQLI_ASSOC)){
$variable = $row;
}
Then later on,
var_dump($variable);
UNDEFINED VARIABLE
Why? I can't see anything wrong with the code. It works if I put a particular value, and I have tested it with WHERE stuff=$item
- that works fine.
So it's not the variables / database, it's an error in the IN statement. I don't understand why it won't work.
</div>