-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.php
More file actions
58 lines (44 loc) · 1.54 KB
/
logic.php
File metadata and controls
58 lines (44 loc) · 1.54 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
<?php
//CONNECTION to Database
$conn = mysqli_connect("localhost","root","password","blog");
if(!$conn) {
echo "<h3 class='container bg-dark text-center p-3
text-warning rounded-lg mt-5'>Not able establish Database Connection</h3>";
}
//SHOW All Posts
$sql = "SELECT * FROM data";
$query = mysqli_query($conn, $sql);
//CREATE Posts
if(isset($_REQUEST["new_post"])) {
$title = $_REQUEST["title"];
$content = $_REQUEST["content"];
$sql = "INSERT INTO data(title, content) VALUES ('$title', '$content')";
mysqli_query($conn, $sql);
header("Location: index.php?info=added");
exit();
}
//SHOW single Post
if(isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];
$sql = "SELECT * FROM data WHERE id = $id";
$query = mysqli_query($conn, $sql);
}
//UPDATE Post
if(isset($_REQUEST['update'])) {
$id = $_REQUEST['id'];
$title = $_REQUEST['title'];
$content = $_REQUEST['content'];
$sql = "UPDATE data SET title = '$title', content = '$content' WHERE id = $id";
mysqli_query($conn, $sql);
header("Location: index.php?info=updated");
exit();
}
//DELETE Post
if(isset($_REQUEST['delete'])){
$id = $_REQUEST['id'];
$sql = "DELETE FROM data WHERE id = $id";
mysqli_query($conn, $sql);
header("Location: index.php?info=deleted");
exit();
}
?>