title: PHP Sign up page
body: <p>Here's registo.php</p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"&gt;
      &lt;link rel="stylesheet" href="css/login.css"&gt;
      &lt;script src="assets/bootstrap/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script src="assets/jquery/jquery-3.2.1.js"&gt;&lt;/script&gt;
      &lt;title&gt;SITIO&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div class="logo"&gt;
              &lt;img src="images/logo_1.png"&gt;
          &lt;/div&gt;
          &lt;div class="login-form"&gt;
              &lt;form action="includes/signup.php" method="post"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label name="username" for="lg_username" class="sr-only"&gt;Username&lt;/label&gt;
                      &lt;input type="text" class="form-control" id="lg_username" name="username" placeholder="username"&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label name="password"for="lg_password" class="sr-only"&gt;Password&lt;/label&gt;
                      &lt;input type="password" class="form-control" id="lg_password" name="password" placeholder="password"&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label name="email" for="lg_email" class="sr-only"&gt;Email&lt;/label&gt;
                      &lt;input type="email" class="form-control" id="lg_email" name="email" placeholder="email"&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                  &lt;button type="submit" name="signup" class="btn btn-block btn-primary"&gt;
                    &lt;/button&gt;
                 &lt;/div&gt;     
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and signup.php</p>
  
  <pre><code>&lt;?php
  
  if(isset($_POST['signup'])){
  
      include "db.php";
  
      $username = $_POST['username'];
      $password = $_POST['password'];
      $email = $_POST['email'];
  
      //Error handlers
      //Check for empty fields
      if(empty($username) || empty($password) || empty($email)){
          header("Location: ../registo.php?=empty");
          exit();
      }else{
          //Validate the email
          if(!filter_var($email, FILTER_VALIDATE_EMAIL){
              header("Location: ../registo.php?=signup=email");
              exit();
          }else{
              //Check if the user already exists
              $sql = "SELECT * FROM Users WHERE username='$username'";
              $r = $conn-&gt;prepare($sql);
              $r-&gt;execute();
              $count = $r-&gt;rowCount();
              if($count &gt; 0){
                  header("Location: ../registo.php?=signup=usertaken");
                  exit();
              }else{
                  //Hash the password
                  $hashedpwd = password_hash($password, PASSWORD_DEFAULT);
                  //Inserting the user into the database
                  $sql="INSERT INTO Users (username, password, email, isAdmin, company_fk) VALUES ('$username', '$hashedpwd', '$email', '0', '2')";
                  $r= $conn-&gt;prepare($sql);
                  $r-&gt;execute();
              }
  
          }
      }
  }else{
      header("Location: ../registo.php?=empty");
      exit();
  }
  </code></pre>
  
  <p>I know I'm still lacking on some basic security checks but no matter how I try to access registo.php I keep getting Error500 on chrome and a blank page on firefox.</p>
  
  <p>The desired result would be for it to load the "registo.php" back if I access it directly (ence the ISSET) or for it to actually add an account to the database.</p>
  
  <p>Taking any advice / suggestions on how to improve it and willing to try anything to make it work since i've been looking at this for a while already and have no idea what is wrong.</p>