-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommentinsert.php
42 lines (37 loc) · 1.12 KB
/
commentinsert.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
include("Connect_Database.php");
?>
<?php
$postInsert = "insert into comments(commenter_id, commenter_name, comment, parent_isbn10, comment_rating) values('" .
$_POST["id"] .
"', '" .
$_POST["name"] .
"', '" .
$_POST["comment"] .
"', '" .
$_POST["isbn10"] .
"', '" .
$_POST["rating"] .
"')";
mysqli_query($connect, $postInsert);
$ratings = 0;
$ratingsSum = 0;
$selectComments = "SELECT * FROM comments c JOIN books b ON c.parent_isbn10 = b.isbn10 WHERE b.isbn10 = " . $_POST["isbn10"];
$resultsComments = mysqli_query($connect, $selectComments);
while($rowComments = mysqli_fetch_assoc($resultsComments)){
$ratingsSum = $ratingsSum + $rowComments["comment_rating"];
$ratings = $ratings + 1;
}
$newRating = number_format(($ratingsSum / $ratings), 1, '.', '');
$updateRating = "UPDATE books SET rating=" . $newRating . " WHERE isbn10=" . $_POST["isbn10"];
mysqli_query($connect, $updateRating);
header("Location: BookInformation.php?isbn10=" . $_POST["isbn10"]);
?>
</body>
</html>