-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinsert.php
More file actions
40 lines (40 loc) · 1.34 KB
/
insert.php
File metadata and controls
40 lines (40 loc) · 1.34 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
<?php
include('db.php');
include('function.php');
if (isset($_POST["operation"])) {
if ($_POST["operation"] == "Add") {
$statement = $connection->prepare("
INSERT INTO articles (author_name, article_text)
VALUES (:author_name, :article_text)
");
$result = $statement->execute(
array(
':author_name' => $_POST["author_name"],
':article_text' => $_POST["article_text"],
)
);
if (!empty($result)) {
// header("location: view_article.php?id=" . $connection->lastInsertId());
$article_title = create_article_title($_POST["article_text"]);
header("location: create_static.php?title=" . $article_title . "&id=" . $connection->lastInsertId());
}
}
if ($_POST["operation"] == "Edit") {
$statement = $connection->prepare(
"UPDATE articles
SET author_name = :author_name, article_text = :article_text
WHERE id = :id
"
);
$result = $statement->execute(
array(
':author_name' => $_POST["author_name"],
':article_text' => $_POST["article_text"],
':id' => $_POST["article_id"]
)
);
if (!empty($result)) {
header("location: view_article.php?id=" . $_POST["article_id"]);
}
}
}