Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('db.php'); // This should initialize a PDO connection, and contain helper functions for queries
- function router() {
- switch($_GET['a']) {
- case ('view'):
- do_view();
- break;
- case ('edit'):
- do_edit();
- break;
- case ('save'):
- $result = do_save();
- if ($result === true) {
- header('location: /?a=view&id='.$GET['id']);
- } else {
- header('location: /?a=view&id='.$GET['id'].'&error='.urlencode($result));
- }
- break;
- }
- }
- function do_view() {
- // Get data here, put it in variables
- include('view.phtml');
- }
- function do_edit() {
- if (empty($_GET['id'])) {
- die("ID is required");
- }
- $id = $_GET['id'];
- // Get data here, put it in variables
- include('edit.phtml');
- }
- function do_save() {
- if (empty($_GET['id'])) {
- die("ID is required");
- }
- if (false) {
- return "Example validation error";
- }
- $id = $_GET['id'];
- // Get the inputs from $_POST, construct a query to save it into pdo
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment