예제 #1
0
<?php

require 'functions.php';
use Blog\DB;
// Connect to the db
$conn = DB\connect($config);
if (!$conn) {
    die('Problem connecting to the db.');
}
// Fetch all the posts
$post = DB\query('SELECT * FROM posts WHERE id = :id LIMIT 1', array('id' => $_GET['id']), $conn)[0];
// Filter through and display in the view
$view_path = 'views/index.view.php';
include 'views/layout.php';
예제 #2
0
<?php

require '../blog.php';
use Blog\DB;
$data = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = $_POST['title'];
    $body = $_POST['body'];
    if (empty($title) || empty($body)) {
        $data['status'] = 'Please fill out both inputs.';
    } else {
        DB\query('INSERT INTO posts(title, body) VALUES (:title, :body)', ['title' => $title, 'body' => $body], $conn);
        $data['status'] = 'Post correctly created';
    }
} else {
    $status = '';
}
view('admin/create', $data);