-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.php
87 lines (66 loc) · 2.71 KB
/
review.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
<html>
<head>
<a href="/">Home</a>
<title>Review</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://unpkg.com/bamboo.css" rel="stylesheet">
</head>
<body>
<?php
$db = new mysqli('localhost', 'cs143', '', 'class_db');
if ($db->connect_errno > 0) {
die('Unable to connect to database [' . $db->connect_error . ']');
}
// REQUIREMENTS
// When the request URL contains only an id parameter like
// http://localhost:8888/review.php?id=705, the page must include input
// boxes to let the user to input their name, the rating of the movie and
// their comment on the movie.
// When the request contains mid, name, rating and comment parameters, you must
// insert a row to the Review table with the provided values. The value for
// the time column should be the time when the review is submitted. The
// returned page from this URL must display “confirmation text” saying that
// the review has been successfully added.
echo "<h1>Add New Review Here:</h1>";
echo "<h2>Movie Title: </h2>";
$movie = "SELECT DISTINCT * FROM Movie WHERE title<>'NULL' AND id={$_GET["id"]}";
$rs = $db->query($movie);
while ($row = $rs->fetch_assoc()) {
$mid = $row['id'];
$title = $row['title'];
echo "<tr>
<td><b>$title</b></td><br><br>
</tr>";
}
function SaveToMyOwnDatabase() {
$db = new mysqli('localhost', 'cs143', '', 'class_db');
if ($db->connect_errno > 0) {
die('Unable to connect to database [' . $db->connect_error . ']');
}
$add_review = "INSERT INTO Review VALUES (\"{$_GET["name"]}\", now(), {$_GET["id"]}, {$_GET["rating"]}, \"{$_GET["comment"]}\")";
$rs2 = $db->query($add_review);
}
?>
<form id="myForm" onSubmit=<?php SaveToMyOwnDatabase() ?>>
<input type="hidden" id="id" name="id" value=<?php echo "{$_GET["id"]}" ?>>
<input type="hidden" id="submitted" name="submitted" value="TRUE" ?>>
<label for="name">Your name:</label>
<input type="text" id="name" name="name" value=<?php echo "{$_GET["name"]}" ?>><br>
<label for="rating">Rating (Out of 10):</label>
<input type="text" id="rating" name="rating" value=<?php echo "{$_GET["rating"]}" ?>><br>
<label for="comment">Comment:</label>
<textarea id="comment" name="comment" value=<?php echo "{$_GET["comment"]}" ?> rows="4" cols="50"></textarea><br><br>
<input type="submit" value="Rating It!">
</form>
<?php
$mid = $_GET["submitted"];
if( $mid === "TRUE"){
echo "Thanks for your comment! Your review has been successfully added. ";
echo "<a href=\"/movie.php?id={$_GET["id"]}\">
click this to go back to see the movie
</a>";
}
?>
</body>
</html>