title: Need help creating a session from database values
body: <p>(Note: have looked at similar questions relating to this but those haven't worked for me in my case)</p>
  
  <p>So the code below is the php for when the user logs in with their username and password. The website has an online currency system. So when they log in I want to try and grab the amount of 'money' that that user has and then turn it into a Session variable so I can use it elsewhere to echo the value.</p>
  
  <p>In this code it creates a session based on the value in the login box. But I want to create a session out of their current 'token' value.</p>
  
  <p>(<a href="https://i.stack.imgur.com/SovoN.png" rel="nofollow noreferrer">Image of Phpmyadmin database</a>) </p>
  
  <p>^ So if I'm trying to log into my acc "Nanikos" I want to get the value of my Tokens from the token column, in this case it's 1000. And then turn that into a session so I can echo that 1000 around the website.</p>
  
  <p>Just not sure how to go about that since I've never tried doing this before aha.    </p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  $servername = "localhost";
  $username = "czt_Nanikos";
  $password = "CZTCb030499";
  
  // Create connection
  $conn = new mysqli($servername, $username, $password);
  
  // Select Database
  mysqli_select_db($conn, "czt_database");
  
  // Check connection
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $uid = mysqli_real_escape_string($conn, $_POST['uid']);
  $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
  
  //Error handlers
      if (empty($uid) || empty($pwd)) {
          header("Location: ../index.php?login=empty");
      } else {    
          $sql = "SELECT * FROM users WHERE user_uid='$uid'";
          $result = mysqli_query($conn, $sql);
          $resultCheck = mysqli_num_rows($result);
          if ($resultCheck &lt; 1) {
              header("Location: ../index.php?login=error");
              exit();
          } else {
              if ($row = mysqli_fetch_assoc($result)) {
                  //De-hashing the password
                  $hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
                  if ($hashedPwdCheck == false) {
                      header("Location: ../index.php?login=error");
                      exit();
                  } elseif ($hashedPwdCheck == true) {
                      //Log in the user
                      $_SESSION["UID"] = $uid;
                      header("Location: ../index.php");
                      exit();
                  }
              }
          }
      }
  {
      header("Location: ../index.php?login=error");
      exit();
  }
  </code></pre>