-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
32 lines (27 loc) · 949 Bytes
/
delete.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
<?php
session_start();
if(isset($_SESSION['id'])){
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8","root","");
$sql = "SELECT p.user_id FROM post as p
WHERE p.id = {$_GET['id']}";
$result = $conn->query($sql);
$row = $result->fetch();
if($_SESSION['role'] == 'a' || $_SESSION['user_id'] == $row['user_id']){
$id = $_GET['id'];
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8","root","");
$sql = "DELETE FROM post WHERE id = $id";
$conn->exec($sql);
$sql = "DELETE FROM comment WHERE post_id = $id";
$conn->exec($sql);
$conn = null;
header("location:index.php");
die();
}else{
header("location:index.php");
die();
}
}else{
header("location:index.php");
die();
}
?>