title: Update session variable in php
body: <p>Okey so i got a problem when a user changes their profile picture. And if I with my silly mind understood correctly (what i think) this is due to my session being not updated... So this is my uploadfile where the user is able to upload a image file to the database, the image gets inserted and it works fine <strong>but</strong> even if the image is changed in the database i still see the old image when i insert it... Only when i logout and login im able to see the new picture,</p>
  
  <ul>
  <li>Is there some type of way i can update my session without the user being logged out in the proccess....?</li>
  <li>Is this due to my session being unupdated? </li>
  </ul>
  
  <p>Don't know if it helps but here is my code </p>
  
  <pre><code>&lt;?php
  if(isset($_FILES['file']) )
  {
  
  move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$_FILES['file']['name']);
  
  session_start();
  $username = $_SESSION['user'];
  $userpic = 'files/'.$_FILES['file']['name'];
  $id = $_SESSION['id'];
  
  include ("connect.php");
  $sql = $con-&gt;prepare('UPDATE users SET username=?, userpic=? WHERE id = ?');
  $sql-&gt;bind_param("ssi",$username,$userpic,$id);
  $sql-&gt;execute(); 
  $sql-&gt;close();
  $con-&gt;close();  
  echo '&lt;div id = "check"&gt; Your image was succesfully uploaded&lt;/div&gt;';
  }
  else{
  echo "no files";}
  ?&gt;
  </code></pre>
  
  <p>And here is my login if that makes it easier as well:</p>
  
  <pre><code>&lt;?php 
  
  include('connect.php');
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  $query = "SELECT * FROM users";
  
  $result = $con-&gt;query($query);
  
  while($row = $result-&gt;fetch_object())
  {
      if($username == $row-&gt;username)
      {
  
              $checkPassword = password_verify($password,$row-&gt;password);
              if($checkPassword ){   // betyder om det är sant
                  session_start();
                  $_SESSION['loggedIn'] = true; 
                  $_SESSION['user'] = $row-&gt;username;
                  $_SESSION['admin'] = $row-&gt;admin;
                  $_SESSION['userpic'] = $row-&gt;userpic;
                  $_SESSION['id'] = $row-&gt;id;
                  header("Location:music.php?success");
                  exit();
                  $fail = false;
              }
  
  
      }
      else{
          $fail = true;
          if($fail){      
      echo "&lt;script&gt;
      alert('You typed in wrong password or username, please try again mate!');
      window.location.href='music.php';
      &lt;/script&gt;";
  
      }
  
      }
  }?&gt;
  </code></pre>
  
  <p>Any help more than appreciated but please try to keep it simple im stupid</p>