title: From Login page to Profile page
body: <p>I did some research here in stackoverflow, but couldn't find the same problem. I have a login page and when the user logs in, it is redirected to profile page. In the profile page  I want to print the name of the user. I am including the file login.php, but I feel for some reason the variable, which contains the username can't be used from login.php in the profile.php. Here is the code:</p>
  
  <p><strong>Login page</strong></p>
  
  <pre><code>&lt;?php
          $host = "XXXX";
          $username = "XXXX";
          $password = "XXXX";
          $db = "XXXX";
  
          $conn = new mysqli($host, $username,$password, $db);
  
          if($conn-&gt;connect_error){
                  die("Connection failed: " . $conn-&gt;connect_error);
          }
  
          error_reporting(E_ALL);
          ini_set('display error', 1);
  
          if(isset($_POST["loginButton"])){
                  $loginUsername = $_POST["loginUsername"];
                  $loginPassword = $_POST["loginPassword"];              
                  $query = "SELECT * FROM user WHERE username='$loginUsername' and password='$loginPassword'";
                  $result = mysqli_query($conn,$query) or die(mysqli_error());
                  $count = mysqli_num_rows($result);
                  if ($count == 1){
                          header("Location:profile.php");
                  }else{
                  echo "Invalid Login Credentials.";
                  }
          }
  ?&gt;
  </code></pre>
  
  <p><strong>Profile page</strong></p>
  
  <pre><code>&lt;?php
  include("login.php");
  error_reporting(E_ALL);
  ini_set('display error', 1);
  
  echo $loginUsername;
  
  $sql = "SELECT username FROM user WHERE username = '$loginUsername' "; 
  $result = mysqli_connect($conn,$sql);
  while($row = mysqli_fetch_assoc($result)){
      echo $username = $row["username"];
  </code></pre>