michaelkirby Posted April 11, 2010 Share Posted April 11, 2010 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? Quote Link to comment Share on other sites More sharing options...
litebearer Posted April 11, 2010 Share Posted April 11, 2010 if the user has not logged out after changing pic, could be a simple caching problem. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 11, 2010 Share Posted April 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
michaelkirby Posted April 12, 2010 Author Share Posted April 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 12, 2010 Share Posted April 12, 2010 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. Quote Link to comment Share on other sites More sharing options...
gevensen Posted April 12, 2010 Share Posted April 12, 2010 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 Quote Link to comment 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.