-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathratePage.php
More file actions
89 lines (69 loc) · 2.88 KB
/
ratePage.php
File metadata and controls
89 lines (69 loc) · 2.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
// include the header
include('header.php')
?>
<form action="ratePage.php" method="POST">
<div class="stars">
<input class="star star-5" id="star-5" type="radio" name="rating" value="5"/>
<label class="star star-5" for="star-5"></label>
<input class="star star-4" id="star-4" type="radio" name="rating" value="4"/>
<label class="star star-4" for="star-4"></label>
<input class="star star-3" id="star-3" type="radio" name="rating" value="3"/>
<label class="star star-3" for="star-3"></label>
<input class="star star-2" id="star-2" type="radio" name="rating" value="2"/>
<label class="star star-2" for="star-2"></label>
<input class="star star-1" id="star-1" type="radio" name="rating" value="1"/>
<label class="star star-1" for="star-1"></label></br>
</br><label for="name">Name:</label>
<input type="text" id="name" name="name"></br>
</br><textarea class="comment" name="comment">Type your comment here.</textarea>
<br>
<input type="submit" name="submitReview" id="submitReview" value="Send">
</div>
</form>
<!-- <form action="ratePage.php" method="POST">
<textarea class="comment" name="comment">Type your comment here.</textarea>
<br>
<input type="submit" name="submitReview" id="submitReview" value="Send">
</form> -->
<?php
if(isset($_POST['submitReview'])) {
// get values from post
$comment = $_POST['comment'];
$rating = $_POST['rating'];
$name = $_POST['name'];
// create sql statement
$sql = "INSERT INTO review (ReviewDescription, Rating, name) VALUES ('$comment', '$rating', '$name')";
// run sql query
$query = mysqli_query($conn, $sql);
// if successful then good else bad
if($query) {
echo '<script type="text/javascript">';
echo 'alert("Successfully saved to database!");';
echo 'window.location.href = "ratePage.php";';
echo '</script>';
} else {
echo '<script type="text/javascript">';
echo 'alert("There was an Error! Try again!");';
echo 'window.location.href = "ratePage.php";';
echo '</script>';
}
}
// retrieve all comments from the database
$sql = "SELECT Name, ReviewDescription, Rating FROM review ORDER BY DateAdded DESC";
$result = mysqli_query($conn, $sql);
// loop through the result set and display each comment
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="comment">';
echo '<div class="name">' . (isset($row['Name']) ? $row['Name'] : '') . '</div>';
echo '<div class="stars">';
for($i = 1; $i <= $row['Rating']; $i++) {
echo '<span class="star">★</span>';
}
echo '</div>';
echo '<p>' . $row['ReviewDescription'] . '</p>';
echo '</div>';
}
// include the footer
include("footer.php");
?>