/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Problem with setting default image

Im trying to put a default image for a profile picture until a user uploads images on to the server and DB : – i know im doing something wrong but have no idea what heres my code: –

[code=php]

$profile_pic = “SELECT profile_pic FROM members WHERE userid=’$profid'”;

$pro = mysql_query($profile_pic);

while($picture = mysql_fetch_array( $pro ))
{
if ($picture != 0){

echo “<img id=’img3′ src=/”.$picture[‘profile_pic’] .”></a> “;

}else{

echo “<img src =’QU.gif’/>”;
}

}

[/code]

Thanks in advance ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@vojaApr 08.2010 — There's only one row returned, so you don't need the while loop.

Also, mysql_fetch_array returns row as an array, so you must check an array element, not the array itself (e.g. $picture['profile_pic'] instead of only $picture).

Here's how the code should look like:

[CODE]
$profile_pic = "SELECT profile_pic FROM members WHERE userid='$profid'";
$pro = mysql_query($profile_pic);
$picture = mysql_fetch_array( $pro );

if ($picture['profile_pic'] != 0){

echo "<img id='img3' src=/".$picture['profile_pic'] ."></a> ";

}else{

echo "<img src ='QU.gif'/>";
}
[/CODE]
Copy linkTweet thisAlerts:
@swl7authorApr 08.2010 — First cheers for replying...

I tried your suggestion but im getting the same as before which is the default picture showing up on all members pages even if they already uploaded there own... would it be easier to add the default profile picture when a user signs up to the website?
Copy linkTweet thisAlerts:
@vojaApr 08.2010 — Have you added the default value for column profile_pic in your mysql database? And, does your upload picture script change the profile_pic value when user uploads a picture?
Copy linkTweet thisAlerts:
@swl7authorApr 08.2010 — The column is empty when the user signs up and I use mysql UPDATE to change the picture
Copy linkTweet thisAlerts:
@vojaApr 08.2010 — Then try $picture['profile_pic']!='' instead of $picture['profile_pic']!=0 . Think it should work now.
Copy linkTweet thisAlerts:
@swl7authorApr 08.2010 — thanks very much solved ? ?
×

Success!

Help @swl7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...