Jump to content

Updating a profile picture


michaelkirby

Recommended Posts

Hi all,

 

I have a way of adding a picture to a profile page for a particular user.

 

When the user changes the profile picture by submitting another picture to the database it stores the link in the dbof the picture.

 

On the profile page the img source is looking for the name of the picture in the db however this works fine however once the picture has been changed the user must log in and out for the picture to change to the new one.

 

Do I need to use some kind of Java script or something in order to get this to dynamically change??

 

Any able to help at all?

Link to comment
Share on other sites

Have you set it to change when a user logs in an out? For me its just a simple refreshing of the page, or going to another page and back again etc.

 

If not, then you could use jQuery refresh.. Maybe, or like 'litebearer' stated, could be just cache problems...

What you could do, change your profile pic, dont logout, clear the cache.. and then refresh the page. This will give you an answer if its a cache problem.

 

How is your profile pic displayed, it is possible that a session of the pic is created when a user gets logged in, so when it is changed.. it doesn't recognise it until next log in. The pic will be displayed by the session value too.. rather than straight from the DB in a query.

Link to comment
Share on other sites

Hi,

 

I have checked and it's not a cache problem, however TeddyKiller I'm using sessions to get the picture name from the database. e.g

 

$filename = $_SESSION['filename'];

 

<img src="upload/<?php echo $filename?>"  align="left"width="150px" height="150px"/>

 

In the database I just store the filename in the user table e.g. car.jpg.

 

So I guess this is the problem.

 

So do I now instead need to create a query straight from the db, but how does this become unique to the person logged in?

 

Would I create a query and at the end say where userid = $userid

 

The $userid coming from the session variable?

 

Can you please advise?

 

Thanks in advance

 

 

Link to comment
Share on other sites

Yes. You'd do..

$query = mysql_query("select * from `users` where `userid`='$userid'");
$row = mysql_fetch_array($query);
echo '<img src="upload/'.$row['filename'].'>"  align="left"width="150px" height="150px

 

Assuming "filename" is the collum for the image in the database anyway.

 

If you want to be lazy, you could create a function for it. So you can just call it by doing "echo display_image($userid);"

for example anyway.

Link to comment
Share on other sites

i had the same problem the easiest solution i found was simply to rename the profile picture

in my case i used the fileid-phptime so i could never get a duplicate name

something like this

12-1254332

when i changed the avatar i saved the picture under for example 12-1254333 and deleted 12-1254332

the browser cache automatically reloads when the page refreshes and the new picture is called for

Link to comment
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.