This repository has been 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 pathinsert.php
78 lines (58 loc) · 1.53 KB
/
insert.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
<?php
require 'start.php';
if (isset($_POST['Insert'])) {
$title = $_POST['title'];
$article = $_POST['article'];
$slug = $_POST['slug'];
//Validation here
$insert = $db->prepare("INSERT INTO `articles`(`title`, `article`, `slug`) VALUES (:title,:article,:slug)");
$insert->execute([
':title' => $title,
':article' => $article,
':slug' => $slug
]);
$article_id = $db->lastInsertId();
$tnt->selectIndex("articles.index");
$index = $tnt->getIndex();
$index->indexBeginTransaction();
$index->insert([
'id' => $article_id,
'title' => $title,
'article' => $article,
'slug' => $slug
]);
$index->indexEndTransaction();
header('Location: display.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Insert</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>Insert records</h2>
<form action="insert.php" method="post">
<div>
<label for="title">Article title</label><br>
<input type="text" name="title" id="title" required>
</div>
<div>
<label for="article">Article body</label><br>
<textarea name="article" id="article" required></textarea>
</div>
<div>
<label for="slug">Article slug</label><br>
<input type="text" name="slug" id="slug" required>
</div>
<div>
<input type="submit" value="Insert" name="Insert">
</div>
</form>
</body>
</html>