Imad Posted July 1, 2008 Share Posted July 1, 2008 Hi guys, I'm having troubles with retrieving users avatars. I created an avatar column in my users table. I'm trying to retrieve each users avatar based on the username they logged in with. Here's what I have: $username_m = $_SESSION['valid_user']; $req = 'SELECT username, avatar FROM users WHERE username =".$username_m." '; $result = mysql_query ($req,$db); while($row = mysql_fetch_assoc($result)) { mysql_real_escape_string($username = stripslashes($row['username'])); mysql_real_escape_string($avatar = stripslashes($row['avatar'])); } I than tried to echo the avatar but it doesn't seem to work. Any ideas? Best Regards. Link to comment https://forums.phpfreaks.com/topic/112785-retrieving-avatar/ Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Why are you escaping the string after you get it from the database? Either way, those mysql_real_escape_string() functions aren't doing anything because the input is passed by value and the result is returned. Anyway, try this code to debug: $username_m = $_SESSION['valid_user']; $req = 'SELECT username, avatar FROM users WHERE username =".$username_m." '; $result = mysql_query ($req,$db) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) echo $row['username'] . ":" . $row['avatar'] . "<br>"; If there isn't an error and no usernames get echoed then your data isn't what you are expecting. Link to comment https://forums.phpfreaks.com/topic/112785-retrieving-avatar/#findComment-579284 Share on other sites More sharing options...
sasa Posted July 1, 2008 Share Posted July 1, 2008 change $req = 'SELECT username, avatar FROM users WHERE username =".$username_m." '; to $req = 'SELECT username, avatar FROM users WHERE username ="'.$username_m.'"'; Link to comment https://forums.phpfreaks.com/topic/112785-retrieving-avatar/#findComment-579291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.