简体   繁体   中英

php avatar image and real image display

I am creating PHP products view page. I want to display products uploaded by user profile pic and if not updated user real image should be displayed avatar image. My script is working but not showing avatar image I have tried to make but it's not working

Here is my code

<?php
    if(isset($_GET['srcid'])) {
        $srcid = $_GET['srcid'];
        if($stmt = $con->prepare("SELECT p.*,c.cat_title,u.username,u.profile_pic,title,desc1,time,img,img1,img2,img3,views,id FROM products AS p 
            JOIN users AS u ON u.user_id= p.user_id
            JOIN category AS c ON c.cat_id = p.cat_id
            WHERE id=?")){
                $stmt->bind_param("s", $srcid);
                $stmt->execute();
            }
    }
    $result = $stmt->get_result();
    if($result->num_rows > 0){
        while($row = $result->fetch_array(MYSQLI_ASSOC)) {

?>

<div class="article">
<?php
    $profile_pic = $row['profile_pic']; 
    if ($profile_pic == '') {
?>

<img src="user/icons/avatar.png " width="100" height="100"  style=" margin-top:-20px; float:left;"/>    

<?php
    }else{
?>

<img src='user/profile_picture/<?php echo  $row['profile_pic'];?>' width='150px' height='130px'  style=' float:left;  border:0px solid #ddd'>
<font color="#f90" style="padding:3px;font-family: 'Oswald';">ARTICLE POSTED BY:</font><a href="profile.php?u=<?php echo  $row['username'];?>"><?php echo  $row['username'];?></a></div>
<p class="v-p1"></p>
<?php 
            }
        }
    }
?>
<div class="uploaded"></div>

null does not always equal '';

try if (strlen(trim($profile_pic)) == 0) {?>

Try var dumping $profile_pic to see what it's contents are, or use empty() instead:

<?php if(empty($profile_pic)) { ?>

This way you're covered whether it's NULL, 0, false or an empty string.

Also, check your image path to make sure it's working. You're currently using a relative path to the image, maybe try the full URL instead just in case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM