I’m trying to return all records from my database where the userID is equal to the logged in user.
I have the following only for some reason its not returning anything, can anybody see any obvious errors?
<?php
$interestsquery = "SELECT *
FROM user_interests
WHERE user_id = $usersClass->userID()";
$result = mysql_query($interestsquery);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "{$row['interest']}";
}
?>
The method call is a complex enough expression that you should probably enclose it in expression interpolation delimiters:
But I also recommend abandoning the primitive PHP/mysql extension and moving to PDO, so you can use query parameters. Then you don’t have to hassle with string interpolation at all, and you gain better habits for writing code that resists SQL injection vulnerabilities.