Jump to content

retrieving avatar


Imad

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.