-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblogPostsController.php
More file actions
58 lines (50 loc) · 1.35 KB
/
Copy pathblogPostsController.php
File metadata and controls
58 lines (50 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require_once 'model_z.php';
#require_once 'db_connect.php';
#require_once 'model_z.php';
function fetchAllBlogPosts()
{
return showAllBlogPosts();
}
function fetchBlogPost($id)
{
return showBlogPost($id);
}
if (isset($_POST['submitNewPost'])) {
// Get form data
$title = $_POST['title'];
$body = $_POST['body'];
$author = $_POST['author'];
$email = $_SESSION['Email'];
if (addBlogPost($title, $author, $body, $email)) {
//redirect to all posts page
header('Location: showAllBlogPosts.php');
} else {
header('Location: addBlogPost.php');
}
}
// Check For Edit Submit
if (isset($_POST['submitEdit'])) {
// Get form data
$update_id = $_POST['update_id'];
$title = $_POST['title'];
$body = $_POST['body'];
$author = $_POST['author'];
if (updateBlogPost($title, $body, $author, $update_id)) {
//redirect to the edited post page
header('Location: showBlogPost.php?id=' . $update_id);
} else {
echo "Error.";
}
}
// Check For delete post
if (isset($_POST['deletePost'])) {
// Get form data
$delete_id = $_POST['delete_id'];
if (deleteBlogPost($delete_id)) {
//redirect to show all posts
header('Location: showAllBlogPosts.php');
} else {
echo "Error.";
}
}