forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_processor.php
More file actions
58 lines (54 loc) · 1.33 KB
/
post_processor.php
File metadata and controls
58 lines (54 loc) · 1.33 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
// iclude functions.php
include 'functions.php';
// operasi
if ($_GET['action']=="edit" || $_GET['action']=="add"){
// mengedit atau menambahkan post
$title = $_POST['Judul'];
$date = $_POST['Tanggal'];
$content = $_POST['Konten'];
$featured = "FALSE";
if(isset($_POST['Featured']))
$featured = "TRUE";
echo $featured;
connect_db();
$row;
if($_GET['action']=="add"){ // menambahkan post
$insertQuery = "INSERT INTO sb_posts (judul, tanggal, konten, featured) VALUES ('" .
$title . "', '" . $date . "', '" . $content . "', " . $featured . ")";
$row = run_query($insertQuery);
}
else{ // mengedit post yang ada
$pid = $_POST['pid'];
$updateQuery = "UPDATE sb_posts SET judul = '" .
$title . "', tanggal = '" . $date . "', konten = '" . $content . "', featured = " . $featured . " WHERE id_post=" . $pid;
$row = run_query($updateQuery);
}
if($row != false){
echo ' berhasil';
}
else{
echo ' gagal';
}
disconnect_db();
header('Location: index.php');
die();
}
else if($_GET['action']=="delete"){
// menghapus post
connect_db();
$query = "DELETE FROM sb_posts WHERE id_post=".$_GET['pid'];
if(run_query($query)){
echo 'post berhasil dihapus';
}
else {
echo 'query salah, post gagal dihapus';
}
disconnect_db();
header('Location: index.php');
die();
}
else {
echo 'tidak ada variable yang diset';
}
?>