Advertisement
EndymionSpr

Untitled

Jan 11th, 2021
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2.   // Headers
  3.   header('Access-Control-Allow-Origin: *');
  4.   header('Content-Type: transaction_type/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/Trades.php';
  10.   // Instantiate DB & connect
  11.   $database = new Database();
  12.   $db = $database->connect();
  13.  
  14.   // Instantiate blog post object
  15.   $trades = new Trades($db);
  16.  
  17.   // Get raw posted data
  18.   $data = json_decode(file_get_contents("php://input"));
  19.  
  20.   $trades->plant_type = $data->plant_type;
  21.   $trades->name = $data->name;
  22.   $trades->town = $data->town;
  23.   $trades->phone = $data->phone;
  24.   $trades->transaction_type = $data->transaction_type;
  25.   $trades->descryption = $data->descryption;
  26.  
  27.   // Create Plant
  28.   if($trades->create()) {
  29.     echo json_encode(
  30.       array('message' => 'Plant Created')
  31.     );
  32.   } else {
  33.     echo json_encode(
  34.       array('message' => 'Plant Not Created')
  35.     );
  36.   }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement