title: Mysqli and Php with session login form keep fail
body: <p>When I hit my submit button to login nothing happens. I am just getting the same page, and not even an error. The connection to db should be fine. I have been looking at the code for 10 hours now, and I cannot figure out why. Does anybody have an idea?</p>
  
  <p>dbconfic.inc.php:</p>
  
  <pre><code>&lt;?php
      $db_host = "localhost";
      $db_user = "root";
      $db_pass = "root";
      $db_name  = "testdb";
      // connection:
      $mysqli = new mysqli($db_host, $db_user, $db_pass , $db_name);
      // tjek conenction:
      if (mysqli_connect_errno()) {
          printf("Connect failed: %s\n", mysqli_connect_error());
      }
  
      // vi kører utf-8 på connection:
      $mysqli-&gt;set_charset("utf-8");  
  ?&gt;
  </code></pre>
  
  <p>index.php:</p>
  
  <pre><code> &lt;?php
  include('login.php'); // Include Login Script
  
  if(isset($_SESSION['username']))
  {
  header('Location: home.php');
  }
  exit();
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;PHP Login Form with Session&lt;/title&gt;
  &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;PHP Login Form with Session&lt;/h1&gt;
  &lt;div class="loginBox"&gt;
  &lt;h3&gt;Login Form&lt;/h3&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;form method="post" action=""&gt;
  &lt;label&gt;Username:&lt;/label&gt;&lt;br&gt;
  &lt;input type="text" name="username" placeholder="username" /&gt;&lt;br&gt;&lt;br&gt;
  &lt;label&gt;Password:&lt;/label&gt;&lt;br&gt;
  &lt;input type="password" name="password" placeholder="password" /&gt;  &lt;br&gt;&lt;br&gt;
  &lt;input type="submit" value="Login" /&gt; 
  &lt;/form&gt;
  &lt;div class="error"&gt;&lt;?php echo $error;?&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.php:</p>
  
  <pre><code>&lt;?php
  session_start();
  include("dbconfic.inc.php"); //Establishing connection with our database
  
  $error = ""; //Variable for storing our errors.
  if(isset($_POST["submit"]))
  {
  if(empty($_POST["username"]) || empty($_POST["password"]))
  {
  $error = "Both fields are required.";
  }else
  {
  // Define $username and $password
  $username=$_POST['username'];
  $password=$_POST['password'];
  
  // To protect from MySQL injection
  $username = stripslashes($username);
  $password = stripslashes($password);
  $username = mysqli_real_escape_string($db, $username);
  $password = mysqli_real_escape_string($db, $password);
  $password = md5($password);
  
  //Check username and password from database
  $sql="SELECT uid FROM users WHERE username='$username' and password='$password'";
  $result=mysqli_query($db,$sql);
  $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
  
  //If username and password exist in our database then create a session.
  //Otherwise echo error.
  
  if(mysqli_num_rows($result) == 1)
  {
  $_SESSION['username'] = $login_user; // Initializing Session
  header("location: home.php"); // Redirecting To Other Page
  }else
  {
  $error = "Incorrect username or password.";
  }
  
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>home.php:</p>
  
  <pre><code>   &lt;?php
      include("check.php");   
  ?&gt;
   &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h1 class="hello"&gt;Hello, &lt;em&gt;&lt;?php echo $login_user;?&gt;!&lt;/em&gt;&lt;/h1&gt;
          &lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;a href="logout.php" style="font-size:18px"&gt;Logout?&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>check.php:</p>
  
  <pre><code>&lt;?php
  include('dbconfic.inc.php');
  session_start();
  $user_check=$_SESSION['username'];
  
  $sql = mysqli_query($db,"SELECT username FROM users WHERE username='$user_check' ");
  
  $row=mysqli_fetch_array($sql,MYSQLI_ASSOC);
  
  $login_user=$row['username'];
  
  if(!isset($user_check))
  {
  header("Location: index.php");
  }
  ?&gt;
  </code></pre>
  
  <p>logout.php</p>
  
  <pre><code>&lt;?php
  session_start();
  if(session_destroy())
  {
  header("Location: index.php");
  }
  
  ?&gt;
  </code></pre>