-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddpost.php
74 lines (56 loc) · 1.66 KB
/
addpost.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once 'includes/global.inc.php';
//check to see if they're logged in
if(!isset($_SESSION['logged_in'])) {
header("Location: login.php");
}
//get the blog object from the session
$user = unserialize($_SESSION['user']);
$blog = unserialize($_SESSION['blog']);
//initialize php variables used in the form
$title = $blog->title;
$message = "";
$category = $blog->category ;
$content = $blog->content ;
//check to see that the form has been submitted
if(isset($_POST['submit-settings'])) {
//retrieve the $_POST variables
$title = $_POST['title'];
$category = $_POST['category'];
$content = $_POST['content'];
//initialize variables for validation
$success = true;
if($success)
{
//prep data
$data['title'] = $title;
$data['category'] = $content;
$data['content'] = $content;
//create new blog object
$newblog = new blog($data);
//save
$newblog->save(true);
}
$message = "Post added<br/>";
}
if(isset($_POST['go-back'])) {
header("Location: index.php");
}
//If the form wasn't submitted, or didn't validate
//then we show the post form again
?>
<html>
<head>
<title>Add Post </title>
</head>
<body>
<?php echo $message; ?>
<form action="addpost.php" method="post">
Title: <input type="text" value="<?php echo $title; ?>" name="title" /><br/>
Category: <input type="text" value="<?php echo $category; ?>" name="category" /><br/>
Content: <textarea type="text" value="<?php echo $content; ?>" name="content"></textarea><br/>
<input type="submit" value="Post" name="submit-settings">
<input type="submit" value="Back" name="go-back" />
</form>
</body>
</html>