Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is the update method in my class
- public function update() {
- $query = 'UPDATE ' . $this->table . ' SET grade = :grade WHERE id = :id';
- $stmt = $this->conn->prepare($query);
- $this->id = htmlspecialchars(strip_tags($this->id));
- $this->grade = htmlspecialchars(strip_tags($this->grade));
- $stmt->bindParam(':id', $this->id);
- $stmt->bindParam(':grade', $this->grade);
- if($stmt->execute()) {
- return true;
- }
- printf("Error: %s.\n", $stmt->error);
- return false;
- }
- This is my update api file.
- <?php
- /**
- * Phoenix Hospitality Management System
- * PHP Script that creates a new grades in the database
- * Copyright (c) Troy Marker Enterprises
- *
- * @copyright Copyright (c) Troy Marker Enterprises
- * @link
- * @since 1.0.0
- * @license
- */
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: application/json');
- header('Access-Control-Allow-Methods: PUT');
- header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
- include_once '../config/Database.php';
- include_once '../models/Grades.php';
- $database = new Database();
- $db = $database->connect();
- $grade = new Grade($db);
- $incoming_id = isset($_POST['id']) ? $_POST['id'] : die("API ERROR: Missing grade id parameter");
- $incoming_grade = isset($_POST['grade']) ? $_POST['grade'] : die("API ERROR: Missing grade name parameter");
- if($grade->update()) {
- echo json_encode(array('message' => 'Grade Updated'));
- } else {
- echo json_encode(array('message' => 'Grade Not Updated'));
- }
Advertisement
Add Comment
Please, Sign In to add comment