title: Update User Info with user id in session
body: <p>I have a project, where users can edit their own profile.
  I currently have a login/register page. Now its time for a user-edit page.
  The site works with <strong>sessions</strong> so, whenever they come back they see myprofile in the navbar. </p>
  
  <p>I've tested everything in PHP, to update the account.</p>
  
  <p>I currently have 2 files where the update-profile scripts works with.</p>
  
  <p><code>1 is the profile.php, the other in includes/update.inc.php</code></p>
  
  <p>In <code>includes/login.inc.php</code> I have already assigned a session.</p>
  
  <pre><code>          if ($pwdCheck == false) {
          header("Location: ../index.php?error=wrongpassword");
          exit();
        }
        else if ($pwdCheck == true) {
          session_start();
          $_SESSION['userId'] = $row['idUsers'];
          $_SESSION['userUid'] = $row['uidUsers'];
  
          header("Location: ../index.php?logging=succes");
          exit();
  </code></pre>
  
  <p>So yeah that was from the <strong>includes/login.inc.php</strong>.</p>
  
  <p>Now when u go to your profile it checks <code>if $_SESSION['userId'] == true.</code></p>
  
  <p>Now the following: </p>
  
  <p>This is my profile.php</p>
  
  <pre><code>    &lt;?php
       require "header.php";
        require "includes/dbh.inc.php";
           $sessionkk = $_SESSION['userId'];
           error_reporting(E_ALL); ini_set('display_errors', 1);
  
        $query = "SELECT idUsers, uidUsers, emailUsers,pwdUsers,Voornaam,Tussenvoegsel,Achternaam,Schooljaar,School,Opleiding,Niveau,Recht,Taal 
   , 
   printerA,printerB,printerC FROM users WHERE idUsers = '$sessionkk'";
     $result = $conn-&gt;query($query) or die($conn-&gt;error);
  
     if(mysqli_num_rows($result) &gt; 0){
     while ($row = mysqli_fetch_assoc($result)){
     $id = $row['idUsers'];
     $username = $row['uidUsers'];
     $email = $row['emailUsers'];
     $password = $row['pwdUsers'];
     $voornaam = $row['Voornaam'];
     $tussenvoegsel = $row['Tussenvoegsel'];
     $achternaam = $row['Achternaam'];
     $Schooljaar = $row['Schooljaar'];
     $School = $row['School'];
     $Opleiding = $row['Opleiding'];
     $niveau = $row['Niveau'];
     $Taal = $row['Taal'];
     $printera = $row['printerA'];
     $printerb = $row['printerB'];
     $printerc = $row['printerC'];
  
  }
  }
  
  
  
  
  
  ?&gt;
  
    &lt;div class="adminform"&gt;
        &lt;h2&gt;gegevens aanpassen&lt;/h2&gt;&lt;br/&gt;
            &lt;form action="includes/update.inc.php" method="POST"&gt;
                &lt;input type="text" name="username" placeholder="Username" 
  value=" 
  &lt;?php if(isset($_GET['username'])){echo $_GET['username'];}?&gt;"&gt;&lt;br/&gt;&lt;br/&gt;
            &lt;input type="text" name="email" placeholder="E-mail" value="&lt;?php 
  if(isset($_GET['email'])){echo $_GET['email'];}?&gt;"&gt;&lt;br/&gt;&lt;br/&gt;
            &lt;input type="text" name="" placeholder="Schooljaar" value="&lt;?php 
  if(isset($_GET['Schooljaar'])){echo $_GET['Schooljaar'];}?&gt;"&gt;&lt;br/&gt;&lt;br/&gt;
            &lt;input type="text" name="email" placeholder="E-mail" value="&lt;?php 
      if(isset($_GET['School'])){echo $_GET['School'];}?&gt;"&gt;&lt;br/&gt;&lt;br/&gt;
            &lt;button type="submit" name="adminupdate"&gt;Aanpassen&lt;/button&gt;
        &lt;/form&gt;
        &lt;?php
          echo "" . $id;
  
         ?&gt;
    &lt;/div&gt;
   &lt;?php
  
   ?&gt; 
  </code></pre>
  
  <p>Here i conclude everything. The formname etc etc. </p>
  
  <p>You can also see how i make a <code>$sessionkk = $_SESSION['userId'];</code></p>
  
  <p>The $sessionkk works with the </p>
  
  <p>Here is the include/update.inc.php</p>
  
  <pre><code>    &lt;?php
      session_start();
         require "dbh.inc.php";
  
  
      if(isset($_POST['adminupdate'])){
  
       $sql = "UPDATE users SET  uidUsers= '?', emailUsers = '?', Schooljaar = 
   '?', 
       School = '?' WHERE idUsers = '.$sessionkk.'";
                   $stmt = mysqli_stmt_init($conn);
                   if(!mysqli_stmt_prepare($stmt, $sql)){
                         header("Location: ../profile.php?error=sqlerror");
                        exit();
                  } else{
                      mysqli_stmt_bind_param($stmt, "ssss", $username, $email, 
            $Schooljaar, $School);
                      mysqli_stmt_execute($stmt);
  
                      header("Location: ../profile.php?update=succes");
                      exit();
                  }
                }
       ?&gt;
  </code></pre>
  
  <p>I tried the $sql query with just the ID from the database so it would be like this: </p>
  
  <pre><code>$sql = "UPDATE users SET  uidUsers= '?', emailUsers = '?', Schooljaar = '?', 
  School = '?' WHERE idUsers = '4'";
  </code></pre>
  
  <p>and this would work.
  But i want to grab the id from the user who is logged in.
  Sorry that the code is so messy, i dont know how to upload code correctly here.</p>
  
  <p>Thank you</p>