title: Post request on Slim Framework
body: <p>Could someone please help me?
  I have this 500 error when making a post request... Can't understand what it is</p>
  
  <p><strong>NOTE: If i run this api on from a rest client Chrome Extension it works Otherwise i get the following error...</strong></p>
  
  <p>The application could not run because of the following error:
  Details
  Type: ErrorException
  Code: 8
  Message: Trying to get property of non-object
  Line:114</p>
  
  <p>Routes:</p>
  
  <pre><code>&lt;?php 
  require 'Slim/Slim.php';
  \Slim\Slim::registerAutoloader();
  $app = new \Slim\Slim();
  $app-&gt;get('/events','getEvents');
  $app-&gt;get('/events/:year/:month', 'getMonth');
  $app-&gt;get('/events/:year/:month/:day','getAllAfter');
  $app-&gt;post('/events', 'addEvent');
  $app-&gt;run();
  </code></pre>
  
  <p>This is My Function:</p>
  
  <pre><code>function addEvent() {
  
  $app = \Slim\Slim::getInstance();
  $request = $app-&gt;request();
  $body = $request-&gt;getBody();
  $event = json_decode($body);
  
  //Line 114
  $submited_date = $submited_date = $event-&gt;{'date_submit'} .' '.$event-&gt;{'time_submit'};   
  $sql = "INSERT INTO events (edate, title, performers, address) VALUES (:edate, :title, :performers, :address)";
  try {
      $conx = getconx();
      $stmt = $conx-&gt;prepare($sql);
      $stmt-&gt;bindParam("edate", $submited_date);
      $stmt-&gt;bindParam("title", $event-&gt;etitle);
      $stmt-&gt;bindParam("performers", $event-&gt;performers);
      $stmt-&gt;bindParam("address", $event-&gt;address);
      $stmt-&gt;execute();
      $event-&gt;id = $conx-&gt;lastInsertId();
      $conx = null;
      $result = array("status"=&gt;"success","events"=&gt;$event);
      echo json_encode($result);
  } catch(PDOException $e) {
      $result = array("status"=&gt;"error","message"=&gt;'Exception: ' . $e-&gt;getMessage());
      echo json_encode($result,JSON_PRETTY_PRINT);
  }
  }
  </code></pre>
  
  <p>This is the json sent:</p>
  
  <pre><code>{
     "date":"24 March, 2014",
     "date_submit":"2014-03-24",
     "time":"4:00 PM",
     "time_submit":"16:00:00",
     "etitle":"Event     Title",
     "performers":"david",
     "address":"Place"
  }
  </code></pre>
  
  <p>jquery code:
  <strong>fixed by using JSON.stringify(); to the data before sending request</strong></p>
  
  <pre><code>     function addEvent(jsondat) {
              console.log('addEvent');
  
              $.ajax({
                  type: 'POST',
                  contentType: 'application/json',
                  url: rootURL,
                  dataType: "json",
                  data: JSON.stringify(jsondat); ,
                  success: function(data, textStatus, jqXHR){
                      alert(Event created successfully');
                  },
                  error: function(jqXHR, textStatus, errorThrown){
                      alert('addEvent error: ' + textStatus);
                  }
              });
          }
          jQuery(document).on('ready', function() {
              jQuery('form#myForm').bind('submit', function(event){
                  event.preventDefault();
                  var form = this;
                  var pson = ConvertFormToJSON(form);
                  //document.write(JSON.stringify(pson));
                  addEvent(pson);
              });
          });
  </code></pre>