php - MySQL Query not selecting data based on WHERE value -


i'm trying return records database userid equal logged in user.

i have following reason not returning anything, can see obvious errors?

<?php  $interestsquery  = "select *                        user_interests                       user_id = $usersclass->userid()"; $result = mysql_query($interestsquery);  while($row = mysql_fetch_array($result, mysql_assoc)) {     echo "{$row['interest']}"; }  ?> 

the method call complex enough expression should enclose in expression interpolation delimiters:

$interestsquery  = "select * user_interests user_id = {$usersclass->userid()}" 

but recommend abandoning primitive php/mysql extension , moving pdo, can use query parameters. don't have hassle string interpolation @ all, , gain better habits writing code resists sql injection vulnerabilities.

$interestsquery  = "select * user_interests user_id = ?" $stmt = $pdo->prepare($interestsquery); $result = $stmt->execute(array( $usersclass->userid() )); 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -