This repository was archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.php
91 lines (67 loc) · 2 KB
/
update.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require 'start.php';
$slug = urldecode($_GET['article']);
$view = $db->prepare("SELECT * FROM `articles` WHERE slug = :slug LIMIT 1");
$view->execute([ ':slug' => $slug ]);
$viewResult = $view->fetch();
$viewId = e($viewResult['id']);
$viewTitle = e($viewResult['title']);
$viewArticle = e($viewResult['article']);
$viewSlug = e($viewResult['slug']);
if (isset($_POST['Update'])) {
$id = $viewId;
$title = $_POST['title'];
$article = $_POST['article'];
$slug = $_POST['slug'];
//Validation here
$update = $db->prepare("UPDATE `articles` SET `title` = :title, `article` = :article, `slug` = :slug WHERE id = :id");
$update->execute([
':id' => $id,
':title' => $title,
':article' => $article,
':slug' => $slug
]);
$tnt->selectIndex("articles.index");
$index = $tnt->getIndex();
$index->indexBeginTransaction();
$index->update($id, [
'id' => $id,
'title' => $title,
'article' => $article,
'slug' => $slug
]);
$index->indexEndTransaction();
header('Location: display.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Update records</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<a href="index.php">Search</a><br>
<a href="insert.php">Insert records</a><br>
<a href="display.php">Display records</a><br>
<br><br>
<h2>Update records</h2>
<form action="update.php?article=<?php echo urlencode($viewSlug); ?>" method="post">
<div>
<label for="title">Article title</label><br>
<input type="text" name="title" id="title" value="<?php echo $viewTitle; ?>">
</div>
<div>
<label for="article">Article body</label><br>
<textarea name="article" id="article"><?php echo $viewArticle; ?></textarea>
</div>
<div>
<label for="slug">Article slug</label><br>
<input type="text" name="slug" id="slug" value="<?php echo $viewSlug; ?>">
</div>
<div>
<input type="submit" value="Update" name="Update">
</div>
</form>
</body>
</html>