title: AngularJS form data not stored in MySQL db
body: <p>In my AngularJS app, the data entered into the form are not stored in the MySQL database after hitting the submit button. An alert after successful form data submit however indicates that it is working.</p>
  
  <p>Also, after hitting the submit button, I want the app to proceed to the next view (#/setup-step2) - however it remains at step1.</p>
  
  <p>html partial (#/setup-step1):</p>
  
  <pre><code>&lt;form ng-submit="submitForm1()"&gt;
  Job title: &lt;input type="text" name="jobtitle" ng-model="formData1.jobtitle"&gt;
  Vacancy ID: &lt;input type="text" name="vacancyid" ng-model="formData1.vacancyid"&gt;
  &lt;button type="submit" class="animatedbutton"&gt; Proceed &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>controller.js:</p>
  
  <pre><code>var ctr = angular.module('myApp.controller', []);
  ctr.controller
  ('Step1Controller', ['$scope', '$routeParams', '$http', function($scope, $routeParams, $http){
   $scope.formData1 = {};
                          $scope.submitForm1 = function() {
                          $http({
                              method: 'POST',
                              url: 'php/setup-step1.php',
                              data: $.param($scope.formData1),
                              headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
                          })
                              .success(function(data){
                                  console.log(data);
                                  alert("It worked");
                              })
                              .error(function(data) {
                                  console.log(data);
                                  alert("It didn't work");
                              })
  
                      }
  }]);
  </code></pre>
  
  <p>setup-step1.php in folder /php:</p>
  
  <pre><code>&lt;?php
  include_once('db.php');
  // Check connection
  if(mysqli_connect_errno())
    {echo '&lt;p&gt;Connection to MySQL server failed: '.mysqli_connect_error().'&lt;/p&gt;';}
  else
    {echo '&lt;p&gt;Connection to MySQL server successful.&lt;/p&gt;';}
  
  $_POST = json_decode(file_get_contents("php://input"), true);
  
  if (empty($_POST['jobtitle'])) 
     {$errors['jobtitle'] = 'Job title is required.';}
  else {
  // Escape user inputs for security
     $jobtitle = $_POST['jobtitle'];
     $vacancyid = $_POST['vacancyid'];
     $data = "INSERT INTO campaign (Job_title, Job_id) VALUES ('$jobtitle','$vacancyid')";mysql_query("INSERT INTO campaign (Job_title, Job_id) VALUES ('$jobtitle', '$vacancyid')");}
  
  if ($connect-&gt;query($data) === TRUE) 
     {$conn-&gt;close();} 
  else 
     {echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;}
  
  exit();
  ?&gt;
  </code></pre>