Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/141560-solved-php-mysql-help-please/
Share on other sites

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

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?

<?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.

 

 

 

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!

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.