update.php 719 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. include '../connection.php';
  3. try {
  4. $params = json_decode(file_get_contents('php://input'));
  5. $statement = $db->prepare('update task set title = :title, list_id = :list_id, due = :due, reminder = :reminder, done = :done, note = :note where id = :id');
  6. foreach($params as $key => &$value) {
  7. $statement->bindParam(":$key", $value);
  8. }
  9. if(!$statement->execute()) {
  10. throw new Exception(implode(', ', $statement->errorInfo()));
  11. }
  12. $jsonResult = array(
  13. 'success' => true,
  14. 'tasks' => $params
  15. );
  16. } catch(Exception $e) {
  17. $jsonResult = array(
  18. 'success' => false,
  19. 'message' => $e->getMessage()
  20. );
  21. }
  22. echo json_encode($jsonResult);
  23. ?>