-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletereply.php
68 lines (55 loc) · 2.1 KB
/
deletereply.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
<?php
session_start();
include 'dbh.php';
$replyId=mysqli_real_escape_string($conn,$_POST['replyId']);
if(isset($_SESSION['id'])){
$userId=mysqli_real_escape_string($conn,$_SESSION['id']);
$stmt= $conn->prepare("SELECT replyByUserId FROM repliestable WHERE replyByUserId=? AND id=?");
$stmt-> bind_param("dd",$UID,$RID);
$UID=$userId;
$RID=$replyId;
$stmt->execute();
$result00=$stmt->get_result();
if($row00=mysqli_fetch_assoc($result00)){
//that means if this user is trying to delete his own answer and not anybody else's
//reducing the number of replies from the comments table by 1
//$sql="SELECT replyToCommentId FROM repliestable WHERE id='$replyId'";
//$result=mysqli_query($conn,$sql);
$stmt= $conn->prepare("SELECT replyToCommentId FROM repliestable WHERE id=?");
$stmt-> bind_param("d",$RID);
$RID=$replyId;
$stmt->execute();
$result=$stmt->get_result();
$row=mysqli_fetch_assoc($result);
$commentId=mysqli_real_escape_string($conn,$row['replyToCommentId']);
//$sql1="UPDATE commentstable SET numberOfReplies=(numberOfReplies-1) WHERE id='$commentId'";
//$result1=mysqli_query($conn,$sql1);
$stmt= $conn->prepare("UPDATE commentstable SET numberOfReplies=(numberOfReplies-1) WHERE id=?");
$stmt-> bind_param("d",$CID);
$CID=$commentId;
$stmt->execute();
$result1=$stmt->get_result();
//deleting the likes for this reply from the replylikestable
//$sql2="DELETE FROM replylikestable WHERE replyId='$replyId'";
//$result2=mysqli_query($conn,$sql2);
$stmt= $conn->prepare("DELETE FROM replylikestable WHERE replyId=?");
$stmt-> bind_param("d",$RID);
$RID=$replyId;
$stmt->execute();
$result2=$stmt->get_result();
//now deleting the reply from the repliestable
//$sql3="DELETE FROM repliestable WHERE id='$replyId'";
//$result3=mysqli_query($conn,$sql3);
$stmt= $conn->prepare("DELETE FROM repliestable WHERE id=?");
$stmt-> bind_param("d",$RID);
$RID=$replyId;
$stmt->execute();
$result3=$stmt->get_result();
echo "success";
}
else{
echo "failure";
}
}else{
echo "failure";
}