forked from AmateurIndian/Vapor_Social_Gaming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreviewing.php
79 lines (70 loc) · 2.87 KB
/
reviewing.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
<?php
$conn = mysql_connect("localhost", "root", "sarj-93") or die("mysql connection is failure.");
mysql_select_db("cs353") or die("Database does not exists.");
if (isset($_POST['submit'])){
$userid = $_GET['id'];
$gameid = $_GET['gameid'];
$rating=$_POST['rating'];
settype($rating, "integer");
$content=mysql_escape_string($_POST['content']);
if (!$_POST['content']| !$_POST['rating']){
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Please fill all the fields')
window.location.href='review.php'
</SCRIPT>");
} else {
$cond_query = "SELECT * FROM Gives WHERE userid = '$userid' and gameid = '$gameid'";
$cond_result = mysql_query($cond_query);
$length = mysql_num_rows($cond_result);
$temp;
if($length > 0) {
while($row = mysql_fetch_assoc($cond_result)) {
foreach($row as $key => $val) {
if($key === 'ratingId') {
$temp = $val;
}
}
}
settype($temp, "integer");
$query0 = "UPDATE `Review` SET `rating` = '$rating' WHERE `review`.`ratingId` = '$temp'";
mysql_query($query0);
$query00 = "UPDATE `Review` SET `content` = '$content' WHERE `review`.`ratingId` = '$temp'";
mysql_query($query00);
} else {
$query = "INSERT INTO `Review` (`ratingId`, `rating`, `content`) VALUES (NULL, '$rating', '$content')";
mysql_query($query);
}
$ratingid;
$subquery = "SELECT * FROM `Review` WHERE `rating` = ".$rating." and `content` = '$content'";
$subresult = mysql_query($subquery);
while($row = mysql_fetch_assoc($subresult)) {
foreach($row as $key => $val) {
if($key === 'ratingId') {
$ratingid = $val;
}
}
}
settype($ratingid, "integer");
$query1 = "INSERT INTO `Gives` (`ratingId`, `userid`, `gameid`) VALUES ('$ratingid', '$userid', '$gameid')";
$result1 = mysql_query($query1);
if($result1){
if($length === 0) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Review added to Game')
window.location.href='home.php?edit=Y&id=$userid'
</SCRIPT>");
} else {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Review to game updated')
window.location.href='home.php?edit=Y&id=$userid'
</SCRIPT>");
}
} else {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Invalid information given.')
window.location.href='home.php?edit=Y&id=$userid'
</SCRIPT>");
}
}
}
?>