-
Notifications
You must be signed in to change notification settings - Fork 6
/
saveRating.php
47 lines (35 loc) · 928 Bytes
/
saveRating.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
<?php
session_start();
include ("dbConfig.php");
$DB = new DBConfig();
$DB -> config();
$dbhandle =$DB -> conn();
$q = "SELECT * FROM `rating` "
."WHERE `rated_by`='".$_SESSION["username"]."' "
."AND `meaning_id`='".$_GET[meaning_id]."' "
."LIMIT 1";
//execute the SQL query and return records
$result = mysql_query($q);
if ($row = mysql_fetch_array($result))
{
$q="UPDATE rating set rating=". $_GET[score]." WHERE `rated_by`='".$_SESSION["username"]."' AND `meaning_id`='".$_GET[meaning_id]."' " ;
print $q;
}
else
{
$q="INSERT INTO rating (rated_by,rating,meaning_id)
VALUES('".$_SESSION["username"]."',". $_GET[score].",".$_GET[meaning_id].")";
}
// Run query
$r = mysql_query($q);
if (!$r)
{
$err= mysql_error();
print $err;
}
else if ($r)
{
print "Rating updated";
}
$DB ->close();
?>