mythic Posted January 20, 2009 Share Posted January 20, 2009 I didn't really know what to call the subject, because I don't know what you'd call my problem, I'm still new to this stuff. Okay, what I'm trying to do is I'm trying to make is so that a user can choose what avatar they want to use in my website. But I'm trying to make the avatar show up after the log in. I did get it to work the other day, but I erased the code (stupidest thing I've ever done). And now I'm trying to get it to work again. <?php $result = mysql_query("SELECT * FROM users WHERE avatar = '$avatar'"); while($row = mysql_fetch_array($result)) { echo "<img src=avatars/"; echo $row['avatar']; echo ".jpg>"; } ?> If you change the 'avatar' stuff so username, and place an image with say the persons username, testing, in the right folder then it shows up and works. Why won't it work if I change the info? And if anyone has a short code which I can use without all that long mumbojumpbo, I'd love them a lot! Quote Link to comment https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/ Share on other sites More sharing options...
RussellReal Posted January 20, 2009 Share Posted January 20, 2009 you never connect to your database, OR select a database also, you wouldn't want to search for WHERE `avatar` = '$avatar' Youw ant to find the username WHERE `username` = '$_SESSION['username']' or however you handle your data Quote Link to comment https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/#findComment-741022 Share on other sites More sharing options...
mythic Posted January 20, 2009 Author Share Posted January 20, 2009 Your confusing. You said you never connect to your database then post something about what it should be. I'm not trying to display the username info, I'm trying to display the avatar. The avatar doesn't share the same name as the username, so that command won't work for me. I already stated what works and what doesn't. I'm trying to get it to work the way I want, or understand why it won't and try to work around it. As I've stated I'm new at this. Can anyone please help? Quote Link to comment https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/#findComment-741044 Share on other sites More sharing options...
priti Posted January 20, 2009 Share Posted January 20, 2009 <?php >> $result = mysql_query("SELECT * FROM users WHERE avatar = '$avatar'"); >>>>Query: If you have $avatar already then why the above query you are executing ?? >> while($row = mysql_fetch_array($result)) { echo "<img src=avatars/"; echo $row['avatar']; echo ".jpg>"; } >>>> Here , if you already have $avatar then you can directly print your image like this: echo '<img src="avatars/'.$avatar.'.jpg"/>' According to me , what your present code will output is <img src=avatars/(value of )$row['avatar'].jpg>" instead it should be printing <img src="avatars/(value of )$row['avatar'].jpg" />.Please check at your end you might have posted a snip of your code this is my guess Kindly confirm at your end. and let us know if it helps. Quote Link to comment https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/#findComment-741079 Share on other sites More sharing options...
mythic Posted January 20, 2009 Author Share Posted January 20, 2009 okay, I got it work. Let me just die.. Y.Y I put the space / in after the image stuff, and it worked. I just have one last thing. What do you mean by: >>>>Query: If you have $avatar already then why the above query you are executing ?? I thought I had to have $result = mysql_query("SELECT * FROM users WHERE avatar = '$avatar'"); to call on the database to get the right info from the right database for the right user o.O or at least that's how I took it from the tutorials I was reading. If I take it out it doesn't work. But if you've got a nicer cleaner safer way where I don't have to post all that jazz then please let me in on it! Quote Link to comment https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/#findComment-741087 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.