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. Quote 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. Quote 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.'"'; Quote Link to comment https://forums.phpfreaks.com/topic/112785-retrieving-avatar/#findComment-579291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.