-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_question.php
93 lines (71 loc) · 2.82 KB
/
delete_question.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php include 'controllers/authController.php';
?>
<br><br><br>
<?php
$post_id=$_GET['del_id'];
$cat_name='';
$cat_id='';
$comment_id='';
$alert_del_que=false;
$username=$_SESSION['username'];
$sql="SELECT `Asked By` FROM `questions` WHERE `S.NO`='$post_id'";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$asked=$row['Asked By'];
if($asked==$username)
{
$sql1="SELECT `Category` FROM `questions` WHERE `S.NO`='$post_id'";
$result1 = mysqli_query($conn, $sql1);
// echo '<pre>' . print_r($result1, TRUE) . '</pre>';
while($rows = mysqli_fetch_assoc($result1))
{
$cat_name = $rows['Category'];
}
$sql2="SELECT `category_id` FROM `categories` WHERE `category_name`='$cat_name'";
$result2 = mysqli_query($conn, $sql2);
while($rows = mysqli_fetch_assoc($result2))
{
$cat_id = $rows['category_id'];
}
$sql3="SELECT `comment_id` FROM `tbl_comment` WHERE `post_id`='$post_id'";
$result3 = mysqli_query($conn, $sql3);
while($rows = mysqli_fetch_assoc($result3))
{
$comment_id = $rows['comment_id'];
$sql="DELETE FROM `rating_info` WHERE `post_id`='$comment_id'";
echo '<pre>' . print_r($sql, TRUE) . '</pre>';
$result = mysqli_query($conn, $sql);
}
$sql="DELETE FROM `questions` WHERE `S.NO`='$post_id'";
$result = mysqli_query($conn, $sql);
// echo '<pre>' . print_r($cat_id, TRUE) . '</pre>';
$sql="DELETE FROM `tbl_comment` WHERE `post_id`='$post_id'";
$result = mysqli_query($conn, $sql);
$sql="DELETE FROM `rating_info` WHERE `post_id`='$post_id'";
// echo '<pre>' . print_r($sql, TRUE) . '</pre>';
$result = mysqli_query($conn, $sql);
if($result=1)
{
$alert_del_que=true;
header("location: http://localhost/iwp/category.php?cat_id=$cat_id");
}
}
else{
$sql1="SELECT `Category` FROM `questions` WHERE `S.NO`='$post_id'";
$result1 = mysqli_query($conn, $sql1);
// echo '<pre>' . print_r($result1, TRUE) . '</pre>';
while($rows = mysqli_fetch_assoc($result1))
{
$cat_name = $rows['Category'];
}
$sql2="SELECT `category_id` FROM `categories` WHERE `category_name`='$cat_name'";
$result2 = mysqli_query($conn, $sql2);
while($rows = mysqli_fetch_assoc($result2))
{
$cat_id = $rows['category_id'];
}
header("location: http://localhost/iwp/category.php?cat_id=$cat_id");
}
}
?>