tlmarker1968

Untitled

Jan 10th, 2020
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. This is the update method in my class
  2.  
  3.         public function update() {
  4.  
  5.             $query = 'UPDATE ' . $this->table . ' SET grade = :grade WHERE id = :id';
  6.  
  7.             $stmt = $this->conn->prepare($query);
  8.  
  9.             $this->id = htmlspecialchars(strip_tags($this->id));
  10.             $this->grade = htmlspecialchars(strip_tags($this->grade));
  11.  
  12.             $stmt->bindParam(':id', $this->id);
  13.             $stmt->bindParam(':grade', $this->grade);
  14.  
  15.             if($stmt->execute()) {
  16.                 return true;
  17.             }
  18.  
  19.             printf("Error: %s.\n", $stmt->error);
  20.  
  21.             return false;
  22.         }    
  23.  
  24. This is my update api file.
  25.  
  26. <?php
  27.     /**
  28.     * Phoenix Hospitality Management System
  29.     * PHP Script that creates a new grades in the database
  30.     * Copyright (c) Troy Marker Enterprises
  31.     *
  32.     * @copyright Copyright (c) Troy Marker Enterprises
  33.     * @link      
  34.     * @since     1.0.0
  35.     * @license  
  36.     */
  37.     header('Access-Control-Allow-Origin: *');
  38.     header('Content-Type: application/json');
  39.     header('Access-Control-Allow-Methods: PUT');
  40.     header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
  41.  
  42.     include_once '../config/Database.php';
  43.     include_once '../models/Grades.php';
  44.  
  45.     $database = new Database();
  46.     $db = $database->connect();
  47.  
  48.     $grade = new Grade($db);
  49.  
  50.     $incoming_id = isset($_POST['id']) ? $_POST['id'] : die("API ERROR: Missing grade id parameter");
  51.     $incoming_grade = isset($_POST['grade']) ? $_POST['grade'] : die("API ERROR: Missing grade name parameter");
  52.  
  53.     if($grade->update()) {
  54.         echo json_encode(array('message' => 'Grade Updated'));
  55.     } else {
  56.         echo json_encode(array('message' => 'Grade Not Updated'));
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment