'I want to display default profile image if user do not have profile image
I am trying to display a default image if user do not have profile image but I am not getting what to do next so.. can any write further code as I tried this code but not working ... thank you in advance
if(!empty($_SESSION['uid'])){$uidval=$_SESSION['uid'];
$getImage=mysqli_query($db, "SELECT user_avatar FROM user where
uid=".$uidval) or die("Could not retrieve image: "
.mysqli_error($db));
$path=mysqli_fetch_assoc($getImage) or die("Could not fetch array : "
.mysqli_error($db));
}
if((isset($_GET['user_avatar']))&&(!empty($_GET['user_avatar']))){
$user_avatar = $_GET['user_avatar'];
}
HTML code
<div class="profile-image">
<img src="<?php echo 'userfiles/avatars/'.$path['user_avatar'];?>" />
</div>
Solution 1:[1]
I think you should add whole PHP code with if and else part. Your question is half! Still let me try if I could answer your question.
For Default image, you should add a image to your upload folder and when you check if profile images is empty or not, in else part, you should add that default static path.
Completing your above question my answer is as below:
if(!empty($path)){
$path='<img src="/image/'.$image.'"/>';
} else {
$path='<img src="/image/default.jpg"/>';
}
Solution 2:[2]
<div>
@if($user)
<img src="{{ $user['user_avatar'] ? $user['user_avatar']:'default_profile_image' }}" alt="user image">
@else
<img src="default_profile_image" alt="user image">
@endif
</div>
I would advise you to query the database and send the whole user object (that contains the property holding the user image) to you your rendering template and have this logic there.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nikhil Parmar |
Solution 2 |