mercredi 26 octobre 2016

Setting the result of an if statement

I am displaying a user's profile image. I have created an if statement to post a default profile image if a user has not updated their own. This is all working, but what I cannot figure out is how to echo or call for each without getting an error for the one not set.

For instance, if they do have a profile picture set, it posts fine, but then I get an error that the other variable is not defined and vise versa.

How should I be calling for this or what changes should I make in my code?

        $pics = array();
        while ($stmt->fetch()) {
            $pics[] = $profilePic;
        }
        if ($profilePic === NULL) {
            $default_profile_img = '<img class="welcome-pic" src="profile_images/default.jpg">';
        } else {
            $set_profile_img = '<img class="welcome-pic" src=" '.$profilePic.'">';
        }
  }
?>
<nav id="nav-panel">
    <div id="nav-container">
            <div id="welcome">
                <?php echo $default_profile_img; 
                echo $set_profile_img; ?>

Aucun commentaire:

Enregistrer un commentaire