8 Replies - 1967 Views - Last Post: 06 April 2010 - 09:25 AM Rate Topic: -----

#1 cmoney12051  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-March 09

help with avatar system

Posted 05 April 2010 - 06:15 AM

on my website im working on implementing an avatar system, where basically users would input their avatar url and it would be saved to the mysql db and then when they login it would show the avatar but im not sure how to do it. I have a avatar row setup in my user table and have put in a test url but i cant figure out how to get it to show on the page. this is at i have so far

<?php
session_start();
require 'database.php';

$avatar = $_GET['avatar'];
$avatar = mysql_query("SELECT * FROM user WHERE avatar = '$avatar'");

if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
echo "<img src=";
echo $avatar;
echo "></img>";
}

?>


but nothing shows up for the image. Please help

Is This A Good Question/Topic? 0
  • +

Replies To: help with avatar system

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: help with avatar system

Posted 05 April 2010 - 11:00 AM

where are you getting the 'get' data from ? i would also reccomend that you try changing the name of one of those avatar variables (i would say make the sql query called $sql or $avatar1 or something else. i think your problem might be that your overiding the variable.

id also make sure that the data in the database is correct too.

thirdly try manually making the avatar show, e.g. get the address of the avatar image and hardcode it into the html to see if it is a specific avatar image that is faulty.
Was This Post Helpful? 1
  • +
  • -

#3 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: help with avatar system

Posted 05 April 2010 - 12:09 PM

You should store the link of the image into the db

Have a table called user_avatars

Then have 2 collums user name and avatars

when they pick the 1 they want use my sql to fill in there user name and the link to the image e.g https://mysite.com/images/mypic.gif

Remember the https ( my site messed up because of it )

The use this bit of code to show the image


$userg      = mysql_query("SELECT * FROM user_avatars WHERE username='$myusername';")
					or die("Failed to fetch your details.");
$user       = mysql_fetch_array($userg);


<img src="http://<?php echo $user['Table_name of link to image'] ?>" width="77" height="80" />





That should work if it works can you thank me :whistling: :whistling:

This post has been edited by nick1200: 05 April 2010 - 12:17 PM

Was This Post Helpful? 1
  • +
  • -

#4 cmoney12051  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-March 09

Re: help with avatar system

Posted 05 April 2010 - 02:26 PM

well i have played with it for a while and i am still unable to get it to even read the image url i put into the database. this is what i have so far

<?php
session_start();
require 'database.php';

$username = $_GET['username'];

$userg      = mysql_query("SELECT avatar FROM user WHERE username = '$username'")

                                        or die("Failed to fetch your details.");
$user       = mysql_fetch_array($userg);


if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
echo "<img src=";
echo $user;
echo "></img>";
echo $user;
echo $userg;

}



?>


and this is what i get

Welcome cmoney12051Resource id #3 


i just cant get this figured out

BTW: i know about the two echos at the bottom i put them there to see if i can atleast read the imge url from the db and then it puts out the Resource id #3 part

This post has been edited by cmoney12051: 05 April 2010 - 02:27 PM

Was This Post Helpful? 0
  • +
  • -

#5 jrm402  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: help with avatar system

Posted 05 April 2010 - 02:59 PM

You are returning an array of information from the db with mysql_fetch_array.

When I want to just return one result, i.e., an avatar path, I use mysql_result($userg, '');.

Maybe this will help you in your troubles. GL :rockon:
Was This Post Helpful? 1
  • +
  • -

#6 cmoney12051  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-March 09

Re: help with avatar system

Posted 05 April 2010 - 03:12 PM

Great! i got it, thanks guys!

<?php
session_start();
require 'database.php';

$username = $_GET['username'];

$userg      = mysql_query("SELECT avatar FROM user")

                                        or die("Failed to fetch your details.");
$user       = mysql_result($userg, '*');


if (isset($_SESSION['user'])){
echo "Welcome ".$_SESSION['user'];
echo "<img src=";
echo $user;
echo "></img>";


}



?>

Was This Post Helpful? 0
  • +
  • -

#7 cmoney12051  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-March 09

Re: help with avatar system

Posted 05 April 2010 - 03:23 PM

now i have to figure out how to have my users insert the image url into their mysql. Im not too good with mysql so any help would be appreciated. i just want to be able to let them insert their avatar url into their username row in the table. any help would be apreciated :)
Was This Post Helpful? 0
  • +
  • -

#8 cmoney12051  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 11-March 09

Re: help with avatar system

Posted 05 April 2010 - 03:35 PM

well i just realized that whenever i change users, the avatar stays the same, how do i get the avatar to change for each user that logs in? man this is getting tough
Was This Post Helpful? 0
  • +
  • -

#9 jrm402  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: help with avatar system

Posted 06 April 2010 - 09:25 AM

What does the INSERT/UPDATE query look like? It would help us to help you if you could post the code of where you edit/save the avatar url to the database.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1