-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.php
More file actions
70 lines (60 loc) · 1.99 KB
/
blog.php
File metadata and controls
70 lines (60 loc) · 1.99 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
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include 'system/start.php';
$auth = new Auth($db);
if(!$auth->isAuthenticated()) {
header('Location: /index.php');
}
$userId = $auth->getUserId();
$userName = $auth->getUserName();
if(isset($_POST['submit'])) {
$articleName = isset($_POST['articleName']) ? check($_POST['articleName']) : '';
$articleDesc = isset($_POST['articleDesc']) ? check($_POST['articleDesc']) : '';
if(!empty($articleName) && !empty($articleDesc)) {
$db->query('INSERT INTO articles
(user_id,
article_name,
article_desc,
created)
VALUES
(' . $userId . ',
"' . $db->escape_string($articleName) . '",
"' . $db->escape_string($articleDesc) . '",
"' . date('Y-m-d H:i:s') . '")
');
}
}
include 'includes/header.php';
?>
<div class="container">
<div class="row">
<div class="col">
<form action="/blog.php" method="POST">
<div class="form-group">
<label for="article">Article name</label>
<input type="text" class="form-control" name="articleName" id="article" placeholder="Article name">
</div>
<div class="form-group">
<label for="text">Text</label>
<textarea name="articleDesc" id="text" class="form-control" placeholder="Text"></textarea>
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-default">
</form>
</div>
<hr>
<ul>
<?php
$dbResult = $db->query('SELECT article_name, article_desc, created FROM articles WHERE user_id = ' . $userId);
while(list($dbArticleName, $dbArticleDesc, $dbCreated) = $db->fetch_row($dbResult)) {
echo '
<li>
<span>' . $userName . ' (' . $dbCreated . ') - <strong>' . $dbArticleName . '</strong></span>
<p>' . $dbArticleDesc . '</p>
</li>
';
}
?>
</ul>
</div>
</div>
</body>
</html>