title: jQuery AJAX request to PHP returns error 500
body: <p>I already know that this is a server error and I am unable to figure out why this is happening. </p>
  
  <p>File structure:</p>
  
  <pre><code>project_manager
      &gt;ajax
          &gt;register.php
      &gt;classes
          &gt;project_manager.php
      &gt;config
          &gt;config.php
      &gt;js
          &gt;scripts.js
      &gt;views
          &gt;register.php
      &gt;index.php
  </code></pre>
  
  <p>My JavaScript is as follows:</p>
  
  <pre><code>if(valid){
      var data = $('#register-form').serializeArray();
      request = $.ajax({
          url: "ajax/register.php",
          type: "post",
          data: data,
          cache: false,
          datatype:'json',
          headers:{"cache-action":"no-cache"}
      }).done(function(data) {
          if(data.success){
              alert('class function worked');
          }
      }).fail(function(data){
          alert('fail')
      });
  }
  </code></pre>
  
  <p>My PHP ajax file is as follows:</p>
  
  <pre><code>&lt;?php
      include_once 'config/config.php';
  
      echo $project_manager-&gt;registerUser($_POST);
  ?&gt;
  </code></pre>
  
  <p>My PHP class file where the function is located is as follows:</p>
  
  <pre><code>class project_manager{
  
      public $connection;
  
      public function registerUser($params){
          // Prepare and Bind
          $stmt = $this-&gt;connection-&gt;prepare('call addUser(?,?,?,?,?,?)');
          $stmt-&gt;bind_param("ssssss", $firstname, $surname, $displayname, $email, $password, $role);
  
          $firstname = $params['firstname'];
          $surname = $params['surname'];
          $displayname = $params['firstname'] + $params['surname'];
          $email = $params['email'];
          $password = $params['password'];
          $role = "test";
  
          $stmt-&gt;execute();
          $stmt-&gt;close();
  
          return json_encode(array("success"=&gt;true));
      }
  
  }
  </code></pre>
  
  <p>The following is in my config file:</p>
  
  <pre><code>&lt;?php
      include "classes/project_manager.php";
      $connection = mysqli_connect($servername, $username, $password, $dbname);
  
      // Check to see if the connection failed
      if($connection === false){
          die("ERROR: Could not connect. ". mysqli_connect_error());
      }
  
      session_start();
  
      $project_manager = new project_manager();
      $database = new database();
      $database-&gt;connection = $connection;
      $project_manager-&gt;connection = $connection;
  ?&gt;
  </code></pre>
  
  <p>My register view code is as follows:</p>
  
  <pre><code>&lt;?php
      $params['firstname'] = 'test';//change with expected values
      $params['email'] = 'test';//change with expected values
      $params['surname'] = 'test';//change with expected values
      $params['password'] = 'test';//change with expected values
  
      //echo $project_manager-&gt;registerUser($_POST);
      echo $project_manager-&gt;registerUser($params);
  ?&gt;
  
  
  
  &lt;form id="register-form" class="user-form"&gt;
       &lt;h2 style="text-align: center; margin-bottom: 30px;"&gt;Register an account&lt;/h2&gt;
       &lt;div class="col-sm-12"&gt;
           &lt;div class="col-sm-6 form-group"&gt;
              &lt;input type='text' name="firstname" class="form-control input-md" placeholder="Firstname..."/&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-6 form-group"&gt;
              &lt;input type='text' name="surname" class="form-control input-md" placeholder="Surname..."/&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-6 form-group"&gt;
              &lt;input type='password' name="password" class="form-control input-md" placeholder="Please Enter A Password"/&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-6 form-group"&gt;
               &lt;input type='password' class="form-control input-md" id="password-confirm" placeholder="Please Confirm Password"/&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-12 form-group"&gt;
              &lt;input type="email" name="email" class="form-control input-md" placeholder="Please Enter An Email Address"/&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-12"&gt;
              &lt;button type="button" id="register" class="btn btn-default pull-right"&gt;Register&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Any sort of help will be much appreciated! </p>