title: MySQL PHP - Fetch data and present in HTML
body: <p>I'm just learning PHP and I'd like to do a basic login. Once logged in, I'd like to show basic information from the user (in this example, just the name), but for some reason I'm not getting the name printed. Could you help me please?</p>
  
  <pre><code>&lt;?php
  include "config.php";
  
  // Session
  if(!isset($_SESSION['uname'])){
      header('Location: login.php');
  }
  // Logout
  if(isset($_POST['but_logout'])){
      session_destroy();
      header('Location: login.php');
  }
  // CHECK THIS
  $sql_query = "select * from users where username='".$uname."'";
  $result = mysqli_query($con,$sql_query);
  $row = mysqli_fetch_array($result);
  ?&gt;
  
  &lt;!doctype html&gt;
  
  &lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
          &lt;form method='post' action=""&gt;
              &lt;h1&gt;Dashboard&lt;/h1&gt;
              &lt;div&gt;
                  &lt;!-- CHECK THIS --&gt;
                  &lt;h2&gt;Hello &lt;?php echo $row['name']; ?&gt;&lt;/h2&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;input type="submit" value="Logout" name="but_logout"&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The login, logout and session are already working.
  The table structure contains a table named users with the columns: id, username, password, name, email.</p>
  
  <p>Thanks</p>