forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote.php
38 lines (28 loc) · 1013 Bytes
/
vote.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
<?php
require_once ("connection.php");
$db = mysql_select_db("tubeswbd", $connect);
$id = $_GET["id"];
$act = $_GET["act"];
$type = $_GET["type"];
$query = sprintf("SELECT votes FROM %s WHERE id=%d",mysql_escape_string($type),mysql_escape_string($id));
$result = mysql_query($query, $connect);
$row = mysql_fetch_array($result, MYSQL_BOTH);
$vote = $row['votes'];
if($act == "up"){
$vote += 1;
$query = sprintf("UPDATE %s SET votes=$vote WHERE id=%d",mysql_escape_string($type),mysql_escape_string($id));
}
else{
$vote -= 1;
$query = sprintf("UPDATE %s SET votes=$vote WHERE id=%d",mysql_escape_string($type),mysql_escape_string($id));
}
$result = mysql_query($query, $connect);
if(!$result){
die('Invalid query: '.mysql_error());
}
$vote = sprintf("SELECT votes FROM %s WHERE id=%d",mysql_escape_string($type),mysql_escape_string($id));
$result = mysql_query($vote, $connect);
$row = mysql_fetch_array($result, MYSQL_BOTH);
echo $row['votes'];
mysql_close($connect);
?>