require_once 'lib/common.php'; require_once 'lib/edit-post.php'; require_once 'lib/view-post.php'; session_start(); //Don't non-auth see this screen if (!isLoggedIn()) { redirectAndExit('index.php'); } //Empty defualts $title = $body = ''; // Init database and get handle $pdo = getPDO(); $postId = null; if (isset($_GET['post_id'])) { $post = getPostRow($pdo, $_GET['post_id']); if ($post) { $postId = $_GET['post_id']; $title = $post['title']; $body = $post['body']; } } // handle the post operation here $errors = array(); if ($_POST) { // Validate these first $title = $_POST['post-title']; if (!$title) { $errors[] = 'The post must have a title'; } $body = $_POST['post-body'];
<?php require_once 'lib/common.php'; require_once 'lib/view-post.php'; session_start(); //Get the post ID if (isset($_GET['post_id'])) { $postId = $_GET['post_id']; } else { //so we always have a post ID var defined $postId = 0; } //Content to db, run query, error handling $pdo = getPDO(); $row = getPostRow($pdo, $postId); $commentCount = $row['comment_count']; //if the post does not exist, lets's deal with that here if (!row) { redirectAndExit('index.php?not-found=1'); } $errors = null; if ($_POST) { switch ($_GET['action']) { case 'add-comment': $commentData = array('name' => $_POST['comment-name'], 'website' => $_POST['comment-website'], 'text' => $_POST['comment-text']); $errors = handleAddComment($pdo, $postId, $commentData); break; case 'delete-comment': $deleteResponse = $_POST['delete-comment']; handleDeleteComment($pdo, $postId, $deleteResponse); break;