Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.