-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_action.php
More file actions
65 lines (62 loc) · 1.42 KB
/
Copy pathadmin_action.php
File metadata and controls
65 lines (62 loc) · 1.42 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
59
60
61
62
63
64
65
<?php
include "db.php";
if(isset($_GET['op']) && $_GET['op']=="delete"){
$id=$_GET['id'];
$query="DELETE FROM post WHERE post_id=$id";
$res=mysqli_query($con,$query);
if($res){
echo 1;
}
else{
echo 0;
}
}
else if(!empty($_FILES['file']['name'])){
$heading=$_POST['heading'];
$desc=$_POST['desc'];
$files=$_FILES['file']['name'];
$target="images/".$_FILES['file']['name'];
if(move_uploaded_file($_FILES['file']['tmp_name'],$target)){
$query="INSERT INTO post VALUES ('','$heading','$desc','$files',now())";
if(mysqli_query($con,$query)){
echo "1";
}
else{
echo "0";
}
}
}
else if($_GET['op']=="edit"){
$id=$_GET['id'];
$query="SELECT * FROM post WHERE post_id='$id'";
$res=mysqli_query($con,$query);
//echo mysqli_error($con);
$arr=[];
if($res){
while($row=mysqli_fetch_row($res)){
$arr[0]=$row[0];
$arr[1]=$row[1];
$arr[2]=$row[2];
//echo $arr[0].$arr[1].$arr[2];
}
echo json_encode($arr);
}
else{
$arr[0]=0;
echo json_encode();
}
}
else if($_GET['op']=="update"){
$id=$_GET['edit_id'];
$edit_heading=mysqli_real_escape_string($con, $_GET['edit_heading']);
$edit_desc=mysqli_real_escape_string($con, $_GET['edit_desc']);
$query="UPDATE post SET post_heading='$edit_heading',post_content='$edit_desc' WHERE post_id='$id'";
$res=mysqli_query($con,$query);
if($res){
echo $_GET['edit_heading'];
}
else{
echo 0;
}
}
?>