-
Notifications
You must be signed in to change notification settings - Fork 1
/
adminreview.php
149 lines (121 loc) · 4.36 KB
/
adminreview.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Reviews</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.review {
margin-top: 20px;
background-color: rgba(0, 0, 0, 0.1);
padding: 15px;
border-radius: 8px;
}
h2 {
margin-top: 0;
color: #333;
border-bottom: 2px solid #333;
padding-bottom: 5px;
}
p {
margin: 10px 0;
}
strong {
font-weight: bold;
}
.delete-btn {
background-color: #ff6666;
color: #fff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
}
.home-button {
position: absolute;
top: 20px;
left: 20px;
background-color: green;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<button class="home-button" onclick="window.location.href='admin.php'">Home</button>
<div class="container">
<h2>All Reviews</h2>
<?php
$conn = new mysqli("localhost", "root", "", "db");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['review_id'])) {
$review_id = $_POST['review_id'];
$sql_delete = "DELETE FROM reviews_ratings WHERE id = ?";
$stmt = $conn->prepare($sql_delete);
$stmt->bind_param("i", $review_id);
if ($stmt->execute()) {
echo "Review deleted successfully.";
} else {
echo "Error deleting review: " . $conn->error;
}
$stmt->close();
}
$sql = "SELECT a.Flatid, a.flat_type, r.id, r.review, r.rating, r.username FROM addproperty a LEFT JOIN reviews_ratings r ON a.Flatid = r.Flatid";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if (!empty($row['review'])) {
echo "<div class='review'>";
echo "<h3>Review ID: " . $row['id'] . "</h3>";
echo "<h4>Flat ID: " . $row['Flatid'] . "</h4>";
echo "<p><strong>Flat Type:</strong> " . $row['flat_type'] . "</p>";
if (!empty($row['username'])) {
echo "<p><strong>User Name:</strong> " . $row['username'] . "</p>";
} else {
echo "<p>No username available.</p>";
}
if (!empty($row['review'])) {
echo "<p><strong>Review:</strong> " . $row['review'] . "</p>";
} else {
echo "<p>No reviews available.</p>";
}
if (!empty($row['rating'])) {
echo "<p><strong>Rating:</strong> " . $row['rating'] . "</p>";
} else {
echo "<p>No ratings available.</p>";
}
echo "<form action='' method='post'>";
echo "<input type='hidden' name='review_id' value='" . $row['id'] . "'>";
echo "<input type='submit' class='delete-btn' value='Delete Review'>";
echo "</form>";
echo "</div>";
}
}
} else {
echo "<p>No reviews and ratings found for any property.</p>";
}
$conn->close();
?>
</div>
</body>
</html>