Skip to content
Snippets Groups Projects
Commit 9a7b56ab authored by Tran Le's avatar Tran Le
Browse files

lab16 complete

parent 6d0b38fd
Branches
No related merge requests found
<?
echo $heading = "<h1>PHP/MySQL Coursework Blog</h1>";
echo $subheading = "<h5>by tle004</h5>";
echo $subheading = "<h4>by tle004</h4>";
error_reporting(E_ALL);
ini_set( "display_errors", 1 );
......@@ -11,7 +11,7 @@
$dbPassword = 'Honguyen57';
//Try to create a connection with database using PDO
//include 'config.php';
include 'config.php';
try {
$pdo = new PDO( $dbInfo, $dbUsername, $dbPassword );
//ensures that PDO throws an exception if there's a problem:
......@@ -41,11 +41,9 @@
$navigation = isset( $_GET['page'] );
if ( $navigation ) {
//prepare to load corresponding controller
$contrl = $_GET['page'];
$contrl = $_GET['page']; //prepare to load corresponding controller
} else {
//or prepare to load default controller
$contrl = "controller";
$contrl = "entries"; //or prepare to load default controller
}
//load the controller
......
INSERT INTO blog_entry(id, title, text, date_created)
VALUES (NULL, 'Hello World!', 'This is an example post.', CURRENT_TIMESTAMP);
\ No newline at end of file
<?
include_once "models/Blog_Entry_Table.class.php";
$entryTable = new Blog_Entry_Table( $pdo );
include_once "models/Blog_Entry_Table.class.php";
$entryTable = new Blog_Entry_Table( $db );
//check if editor form was submitted
$editorSubmitted = isset( $_POST['action'] );
if ( $editorSubmitted ) {
$buttonClicked = $_POST['action'];
//was "save" button clicked
$insertNewEntry = ( $buttonClicked === 'save' );
if ( $insertNewEntry ) {
$title = $_POST['title'];
$entry = $_POST['entry'];
//save the new entry
$entryTable->saveEntry( $title, $entry );
}
}
include_once "views/admin/editor-html.php";
//check if editor form was submitted
$editorSubmitted = isset( $_POST['action'] );
if ( $editorSubmitted ) {
$buttonClicked = $_POST['action'];
$insertNewEntry = ( $buttonClicked === 'save' ); //was "save" button clicked
if ( $insertNewEntry ) {
$title = $_POST['title'];
$entry = $_POST['entry'];
$entryTable->saveEntry( $title, $entry ); //save the new entry
}
}
include_once "views/admin/editor-html.php";
?>
\ No newline at end of file
<?
include_once "models/Blog_Entry_Table.class.php";
$entryTable = new Blog_Entry_Table( $pdo );
$allEntries = $entryTable->getAllEntries();
echo "here's the entries!";
include_once "models/Blog_Entry_Table.class.php";
$entryTable = new Blog_Entry_Table( $db );
$allEntries = $entryTable->getAllEntries();
include_once "views/admin/entries-html.php";
include_once "views/admin/entries-html.php";
?>
\ No newline at end of file
DROP TABLE IF EXISTS blog_entry;
CREATE TABLE blog_entry (
id INT AUTO_INCREMENT,
title VARCHAR(140) NOT NULL,
......
index.php 100644 → 100755
<?
?>
\ No newline at end of file
......@@ -10,8 +10,7 @@ class Blog_Entry_Table {
//Insert new entries
public function saveEntry ( $title, $text ) {
$entrySQL = "INSERT INTO blog_entry (title, text)
VALUES ( ?, ?)";
$entrySQL = "INSERT INTO blog_entry (title, text) VALUES (?, ?)";
$entryStatement = $this->db->prepare( $entrySQL );
$formData = array( $title, $entry );
......@@ -26,7 +25,7 @@ class Blog_Entry_Table {
//Get all entries
public function getAllEntries () {
$entrySQL = "SELECT id, title, SUBSTRING(text, 1, 140) AS intro FROM blog_entry";
$entrySQL = "SELECT id, title, SUBSTRING(text, 1, 140) AS intro FROM blog_entry";
$statement = $this->db->prepare( $entrySQL );
try{
$statement->execute();
......
<?php
$content = "
<form method='post' action='admin.php?page=editor' id='editor'>
<fieldset>
<legend>New Entry Submission</legend>
<label>Title</label>
<input type='text' name='title' maxlength='150' />
<label>Entry</label>
<textarea name='entry'></textarea>
<fieldset id='editor-buttons'>
<input type='submit' name='action' value='save' />
</fieldset>
</fieldset>
</form>
";
$content = "<form method='post' action='admin.php?page=editor' id='editor'>
<fieldset>
<legend>New Entry</legend>
<label>Title</label>
<input type='text' name='title' maxlength='150' />
<br/>
<label>Entry</label>
<textarea rows='10' cols='100' name='entry'></textarea>
<fieldset id='editor-buttons'>
<input type='submit' name='action' value='Submit' />
</fieldset>
</fieldset>
</form>
";
echo $content;
?>
\ No newline at end of file
......@@ -4,7 +4,7 @@ $entriesAsHTML = "<ul>";
//get the entries and display them as a list
while ( $entry = $allEntries->fetchObject() ) {
$href = "admin.php?page=editor&amp;id=$entry->entry_id";
$href = "admin.php?page=editor&amp;id=$entry->id";
$entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>";
}
$entriesAsHTML .= "</ul>";
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment