Guest User

Untitled

a guest
Dec 23rd, 2020
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. include('db.php'); // This should initialize a PDO connection, and contain helper functions for queries
  4.  
  5. function router() {
  6. switch($_GET['a']) {
  7. case ('view'):
  8. do_view();
  9. break;
  10. case ('edit'):
  11. do_edit();
  12. break;
  13. case ('save'):
  14. $result = do_save();
  15. if ($result === true) {
  16. header('location: /?a=view&id='.$GET['id']);
  17. } else {
  18. header('location: /?a=view&id='.$GET['id'].'&error='.urlencode($result));
  19. }
  20. break;
  21. }
  22. }
  23.  
  24. function do_view() {
  25. // Get data here, put it in variables
  26. include('view.phtml');
  27. }
  28.  
  29. function do_edit() {
  30. if (empty($_GET['id'])) {
  31. die("ID is required");
  32. }
  33. $id = $_GET['id'];
  34. // Get data here, put it in variables
  35. include('edit.phtml');
  36. }
  37.  
  38. function do_save() {
  39. if (empty($_GET['id'])) {
  40. die("ID is required");
  41. }
  42. if (false) {
  43. return "Example validation error";
  44. }
  45. $id = $_GET['id'];
  46. // Get the inputs from $_POST, construct a query to save it into pdo
  47. return true;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment