title: Login script for using PHP and SQL Server
body: <p>I am new to PHP and can't figure out what is wrong with my script. Looked everywhere online but it still isn't working. I have a simple login form:</p>
  
  <p>Email:</p>
  
  <p>Password:</p>
  
  <p>And a sign in button in html.</p>
  
  <pre><code>&lt;?php
  
  #starts a new session
  session_start();
  
  #includes a database connection
  $serverName = "ServerNamehere"; //serverName\instanceName
  $connectionInfo = array( "Database"=&gt;"DatabaseNameHere", 
  "UID"=&gt;"ServerUsernameHere", "PWD"=&gt;"ServerPasswordHere");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  
  if( $conn ) {
   echo "Connection established.&lt;br /&gt;";
  }else{
   echo "Connection could not be established.&lt;br /&gt;";
   die( print_r( sqlsrv_errors(), true));
  
  #catches user/password submitted by html form
  $email = $_POST['email'];
  $password = $_POST['password'];
  
  #checks if the html form is filled
  if(empty($_POST['email']) || empty($_POST['password'])){
  echo "Fill all the fields!";
  }else{
  
  #searches for email and password in the database
  $query = "SELECT * FROM [dbo].[Test] WHERE UserEmail(SQL Table 
  column)='{$email}' AND"
       "UserPassword(SQL table column)='{$password}';
  $result = sqlsrv_query($conn, $query);  
  
  #checks if the search was made
  if($result === false){
   die( print_r( sqlsrv_errors(), true));
  }
  
  #checks if the search brought some row and if it is one only row
  if(sqlsrv_has_rows($result) != 1){
     echo "Email/password not found";
  }else{
  
  #creates sessions
  while($row = sqlsrv_fetch_array($result)){
     $_SESSION['id'] = $row['id'];
     $_SESSION['name'] = $row['name'];
     $_SESSION['user'] = $row['user'];
     $_SESSION['level'] = $row['level'];
  }
  #redirects user
  header("Location: homepage.html");
  }
  }
  
  ?&gt;
  </code></pre>
  
  <p>My html connects to this php file through</p>
  
  <pre><code>form class="login-form" name = 'signin.php'&gt;
  </code></pre>
  
  <p>At the moment, when i enter the correct credentials and click sign in nothing happens. Is there anything huge i am missing here that i should check first?</p>
  
  <p>Thanks</p>