注册后,只有在我注销并再次登录后,我的用户的个人资料图片才会显示

我有一个注册表单,其中包含图像的上传,它可以工作,可以上传图像,但是我只能在用户注销并再次登录后在用户页面中看到它。但是,这仅在图像上发生,名称在注册后显示。谢谢!

个人资料页面的代码


if (!isset($_SESSION['email'])) {
  $sql = "SELECT username, image FROM user WHERE email='".$_SESSION['email']."'";

  header('location: login.php');
}


    if (isset($_GET['logout'])) {
        session_destroy();
        unset($_SESSION['email']);
        header("location: login.php");
  }

?>
<body>
                  <div class="welcome">
                  <?php  if (isset($_SESSION['email'])) : ?>
                <p>Bem-vindo(a)<p>
                    <h4><?=((isset($_SESSION['username']))?$_SESSION['username']:"");?></h4>
                    <?php endif ?>
                  </div>

                  <?php  if (isset($_SESSION['email'])) : ?>
                  <div class="foto">
                  <input type="hidden" name="email" value="<?= $_SESSION['email'] ?>">
                    <img src="data:image/jpeg;base64,<?php echo base64_encode($_SESSION['image']); ?>" /></div>
                <?php endif ?>



                          <?php  if (isset($_SESSION['email'])) : ?>
                            <p> <a href="login.php?logout='1'" style="color: green;font-size: 15px;">logout</a> </p>
                            <?php endif ?>

                    </div>

</body>

和服务器页面

<?php 
    session_start();
    $username = "";
    $email    = "";
    $errors = array(); 
    $_SESSION['success'] = "";


    $db = mysqli_connect('localhost','root', '','carsolve') or die("Nao conseguiu conectar à base de dados");

    // REGISTER USER
    if (isset($_POST['reg_user'])) {

        $email = mysqli_real_escape_string($db, $_POST['email']);
        $username = mysqli_real_escape_string($db, $_POST['username']);
        $password = mysqli_real_escape_string($db, $_POST['password']);
        $phone = mysqli_real_escape_string($db, $_POST['phone']);
        $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));


        $user_check_query = "SELECT * FROM user WHERE  email = '$email' LIMIT 1";

        $result = mysqli_query($db, $user_check_query);
        $user = mysqli_fetch_assoc($result);

        if($user){

        if($user['email'] === $email){
            array_push($errors, "Este email já existe.");
            }

        }

        // register user if there are no errors in the form
        if(count($errors) == 0){
            $password = md5($password);
            $query = "INSERT INTO user (username, email, password, phone, image)
             VALUES ('$username' , '$email' , '$password', '$phone', '$image')";

            mysqli_query($db,$query);

            $_SESSION['email'] = $email;
            $_SESSION['username'] = $username;
            $_SESSION['phone'] = $phone;
            $_SESSION['image'] = $image;
            $_SESSION['success'] = "You are Logged";

            header('location: explicaçao1.php');
        }

    }

    // ... 

    // LOGIN USER
    if(isset($_POST['login_user'])){
        $email = mysqli_real_escape_string($db , $_POST['email']);
        $password = mysqli_real_escape_string($db , $_POST['password']);    

        if(count($errors) == 0){
            $password = md5 ($password);

            $query = "SELECT * FROM user WHERE email ='$email' AND password='$password' ";
            $result = mysqli_query($db,$query);
            $row = mysqli_fetch_assoc($result);  

            if(mysqli_num_rows($result)){
                $_SESSION['email'] = $email;
                $_SESSION['username'] = $row['username']; 
                $_SESSION['image'] = $row['image']; 
                $_SESSION['phone'] = $row['phone']; 
                $_SESSION['success'] = "Login com sucesso";
                header('location: page1.php');
            }else{
                array_push($errors, "Email e/ou Password incorretos.");
            }
        }
    }



    ?>