title: To create a login form using php, mysql and html
body: <p>I want to create a working login form. Here's what I have done and this displays cannot select db. </p>
  
  <p>Edited login.php file</p>
  
  <pre><code>&lt;?php
      error_reporting(E_ALL);
      //Connection Variables:
      $dbhost = "localhost";
      $dbname = "";
      $dbuser = "";
      $dbpass = "";
  try{
      //Connection to SQL:
          $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $dbuser, $dbpass);
      //Error messagin enabled:
          $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      }
      catch (PDOException $e)
      {
          echo $e-&gt;getMessage();
      }
  
  
      $user = '';
      $pass = '';
      $sum = 0;
      $error_msg = "Please type a username and a password";
      if(isset($_POST['login']))
      {
          //Start a session:
          session_start();
  
          $user = $_POST['email'];
          $pass = $_POST['password'];
          if(empty($user) &amp;&amp; empty($pass))
          {
              echo $error_msg;
              $pass = '';
          }
          if(empty($user) || empty($pass))
          {
              echo $error_msg;
              $user = '';
              $pass = '';
          }
          if(!empty($user) &amp;&amp; !empty($pass))
          {
              //SQL:
              $query = $conn-&gt;prepare("SELECT * FROM login WHERE user = :u AND password= :p LIMIT 1");
              $query-&gt;bindParam(":u", $user);
              $query-&gt;bindParam(":p", $pass);
              //Execute query:
              $query-&gt;execute();
              $number_rows = $query-&gt;fetch(PDO::FETCH_NUM);
              if($number_rows&gt;0)
              {
                  echo $user;
                  $_SESSION['usern'] = $user;
                  $_SESSION['passw'] = $pass;
                  header("Location: ./pages/home.php");
              }
              //echo $user;
              else
              {
                  echo "Invalid username or password";
                  header("Location: index.html");
              }
          }
      }
      if(!isset($_POST['login']))
      {
          echo "Login button not clicked";
      }
  ?&gt;
  </code></pre>
  
  <p>I read more and more articles on this, still I can't find a solution. </p>
  
  <p>Edited HTML</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --&gt;
      &lt;meta name="description" content=""&gt;
      &lt;meta name="author" content=""&gt;
      &lt;link rel="icon" href="../../favicon.ico"&gt;
  
      &lt;title&gt;Signin for OTMS&lt;/title&gt;
  
      &lt;!-- Bootstrap core CSS --&gt;
      &lt;link href="css/bootstrap.min.css" rel="stylesheet"&gt;
  
      &lt;!-- Custom styles for this template --&gt;
      &lt;link href="signin.css" rel="stylesheet"&gt;
  
      &lt;!-- Just for debugging purposes. Don't actually copy these 2 lines! --&gt;
      &lt;!--[if lt IE 9]&gt;&lt;script src="../../assets/js/ie8-responsive-file-warning.js"&gt;&lt;/script&gt;&lt;![endif]--&gt;
      &lt;script src="js/ie-emulation-modes-warning.js"&gt;&lt;/script&gt;
  
      &lt;!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --&gt;
      &lt;!--[if lt IE 9]&gt;
        &lt;script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"&gt;&lt;/script&gt;
        &lt;script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"&gt;&lt;/script&gt;
      &lt;![endif]--&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
  
      &lt;div class="container"&gt;
  
        &lt;form action="login.php" method="post" class="form-signin"&gt;
          &lt;h2 class="form-signin-heading"&gt;Please sign in&lt;/h2&gt;
          &lt;label for="inputEmail" class="sr-only"&gt;Email address&lt;/label&gt;
          &lt;input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus&gt;
          &lt;label for="inputPassword" class="sr-only"&gt;Password&lt;/label&gt;
          &lt;input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required&gt;
          &lt;div class="checkbox"&gt;
            &lt;label&gt;
              &lt;input type="checkbox" value="remember-me"&gt; Remember me
            &lt;/label&gt;
          &lt;/div&gt;
          &lt;button class="btn btn-lg btn-primary btn-block" type="submit" name="login"&gt;Sign in&lt;/button&gt;
        &lt;/form&gt;
  
      &lt;/div&gt; &lt;!-- /container --&gt;
  
  
      &lt;!-- IE10 viewport hack for Surface/desktop Windows 8 bug --&gt;
      &lt;script src="assets/js/ie10-viewport-bug-workaround.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please help me to find what is the error. 
  I created my database using phpMyAdmin and it's in localhost. And interfaces I designed using Bootstrap.</p>
  
  <p>This is the error I'm getting now:</p>
  
  <p><a href="https://i.stack.imgur.com/Mzzm1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mzzm1.png" alt="enter image description here"></a></p>
  
  <pre><code>database name- otmsdb
  table name- login
  email, passowrd, 
  button name- login
  </code></pre>