-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 1 Sample Code
More file actions
164 lines (150 loc) · 4.23 KB
/
Day 1 Sample Code
File metadata and controls
164 lines (150 loc) · 4.23 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
include('articles_functions.php');
include('mysql.php');
$db = init_db();
#$articles = loadArticles();
if (isset($_GET['id'])) {$id = $_GET['id'];}
else { $id="";}
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
delete_article_from_db ($db, $id);
}
# 11. Make a Form to add a new Blog Article.
# form added to the bottom
/*$articles = array(
array(
'title' => 'My Blog Article',
'author' => 'Ryan',
'date' => 'Mar 10, 2015',
'content' => '<p>This is my first blog article so I\'m a little nervous. Blogs seem really good and hopefully there will be more to come. Ok, here goes...</p>'
),
array(
'title' => 'Other Blog Article',
'author' => 'Mark',
'date' => 'Mar 12, 2015',
'content' => '<p>SxSW is here. Ughhhh..... I mean YEAH!!! Good for the economy! Bad for traffic...</p>'
),
array(
'title' => 'Went Camping',
'author' => 'Other Author',
'date' => 'Mar 13, 2015',
'content' => 'I went camping and got chased by a bear.'
)
);
*/
if (count($_POST) > 0
&& $_POST['title'] != ""
&& $_POST['author'] != ""
&& $_POST['content'] != "") {
# if statement to update the edited article
if (isset($_POST['edited'])) {
$id = $_POST['edited'];
unset($_POST['edited']);
save_existing_article_to_db($db, $_POST, $id);
#$pos = findArticlePosById($articles, $id);
#$articles[$pos] = $_POST;
} else {
$article = $_POST;
save_article_to_db($db, $article);
}
}
$articles = load_articles_from_db($db);
# need to figure out what this else if statement should beelseif () {
?>
<!DOCTYPE html>
<html>
<head>
<title>Chris's Blog</title>
<link href="/123.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
function deleteIfSure(link) {
pressedOK = confirm('You are about to delete the selected article.')
if(pressedOK){
document.location = link;
}
}
</script>
<style>
a:link {
color: rgb(150,150,150);
background-color:transparent;
text-decoration:none;
}
a:visited {
color: rgb(150,150,150);
background-color:transparent;
text-decoration:none;
}
a:hover {
color: white;
background-color:transparent;
text-decoration:none;
}
a:active {
color: white;
background-color:transparent;
text-decoration:none;
}
body {
margin-bottom: 20em;
}
#article-form .form-field {
margin-top: 1em;
margin-bottom: 1em;
}
#article-form textarea {
width: 80%;
height: 10em;
}
</style>
</head>
<body>
<h1 CLASS="funkyclass" ALIGN="center" id="top">Chris's Blog</h1>
<div align="center">
<?php
if (file_exists('articles.file') && count($articles)>1) {
?>
<h2>Previous Entries</h2>
<ul>
<?php
foreach ($articles as $article) {
$id = $article['article_id'];
?>
<li>
<a href="#<?php echo $id; ?>"><?php echo $article['title'] ?></a>
</li>
<?php
}
}
?>
</ul>
<?php # echo all the $articles using a foreach loop ?>
<?php
foreach ($articles as $article) {
echoArticle($article);
}
?>
<h2>Write a new Article!</h2>
<form id="article-form" action="/blogproject2.php" method="post">
<div class="form-row">
<label for="title">Title:</label><br>
<input name="title">
</div><br>
<div class="form-row" id="author-date-fields">
<div>
<label for="author">Author:</label><br>
<input name="author">
</div>
</div><br>
<div class="form-row">
<label for="content">Content:</label><br>
<textarea name="content">
</textarea>
</div><br>
<div class="form-row">
<input type="submit" value="Publish">
</div>
</form>
</body>
</html>