EndymionSpr

Untitled

Jan 15th, 2021
817
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // Headers
  3.   header('Access-Control-Allow-Origin: *');
  4.   header('Content-Type: application/json');
  5.   header('Access-Control-Allow-Methods: POST');
  6.   header('Access-Control-Allow-Headers: Access-Control-Allow-Headers, Content-Type, Access-Control-Allow-Methods, Authorization,X-Requested-With');
  7.  
  8.   include_once '../../config/Database.php';
  9.   include_once '../../models/Comments.php';
  10.   // Instantiate DB & connect
  11.   $database = new Database();
  12.   $db = $database->connect();
  13.  
  14.   // Instantiate comments object
  15.   $comments = new Comments($db);
  16.  
  17.   // Get raw posted data
  18.   $data = json_decode(file_get_contents("php://input"));
  19.  
  20.   $comments->nickname = $data->nickname;
  21.   $comments->comment = $data->comment;
  22.   $comments->forum_id = $data->forum_id;
  23.  
  24.   // Create comment
  25.   if($comments->create()) {
  26.     echo json_encode(
  27.       array('message' => 'Plant Created')
  28.     );
  29.   } else {
  30.     echo json_encode(
  31.       array('message' => 'Plant Not Created')
  32.     );
  33.   }
  34.  
RAW Paste Data