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

adding new entries to database now working. yayy

parent 9a7b56ab
Branches
No related merge requests found
......@@ -3,16 +3,36 @@
$entryTable = new Blog_Entry_Table( $pdo );
//check if the fields are completed or not. if not, print the message to ask user to fill them in
if (empty($_POST['entry_title'])) {
echo "<br/>Please enter a title.";
} else {
echo "";
}
if (empty($_POST['entry_content'])) {
echo "<br/>Please enter entry content (Maximum 140 characters).";
} else {
//check if the user exceeds character limit
if (strlen($_POST['entry_content']) > 140) {
echo "<br/> Please reduce characters (Max: 140).";
} else {
echo "";
}
}
//check if editor form was submitted
$editorSubmitted = isset( $_POST['action'] );
if ( $editorSubmitted ) {
$buttonClicked = $_POST['action'];
$insertNewEntry = ( $buttonClicked === 'save' ); //was "save" button clicked
$insertNewEntry = ( $buttonClicked === 'submit' ); //was "save" button clicked
if ( $insertNewEntry ) {
$title = $_POST['title'];
$entry = $_POST['entry'];
$entryTable->saveEntry( $title, $entry ); //save the new entry
$entry_title = $_POST['entry_title'];
$entry_content = $_POST['entry_content'];
$entryTable->saveEntry( $entry_title, $entry_content ); //save the new entry
echo "Entry successfully added. Go to All Entries to view your entries.";
}
}
......
......@@ -12,10 +12,11 @@ class Blog_Entry_Table {
public function saveEntry ( $title, $text ) {
$entrySQL = "INSERT INTO blog_entry (title, text) VALUES (?, ?)";
$entryStatement = $this->db->prepare( $entrySQL );
$formData = array( $title, $entry );
$formData = array( $title, $text );
try {
$entryStatement->execute( $formData );
// echo "Entry successfully added. Go to All Entries to view.";
} catch (Exception $e){
$msg = "<p>You tried to run this sql: $entrySQL<p>
<p>Exception: $e</p>";
......
......@@ -3,13 +3,13 @@ $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' />
<input type='text' name='entry_title' maxlength='140' />
<br/>
<label>Entry</label>
<textarea rows='10' cols='100' name='entry'></textarea>
<textarea rows='10' cols='100' name='entry_content'></textarea>
<fieldset id='editor-buttons'>
<input type='submit' name='action' value='Submit' />
<input type='submit' name='action' value='submit' />
</fieldset>
</fieldset>
</form>
......
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