-
Notifications
You must be signed in to change notification settings - Fork 0
/
setRecord.php
29 lines (28 loc) · 1.02 KB
/
setRecord.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
<?php
require("config.inc.php");
$filename = "";
$like = "";
if(isset($_REQUEST["filename"]))
$filename = $_REQUEST["filename"];
if(isset($_REQUEST["like"]))
$like = $_REQUEST["like"];
$mysqli = new mysqli("localhost", __DB_USER__, __DB_PASSWORD__, __DB_NAME__);
$result = $mysqli->query("SELECT likes, dislikes FROM records WHERE filename = '".$mysqli->real_escape_string($filename)."';");
if($result->num_rows !=0){
$row = $result->fetch_assoc();
$likes = $row["likes"];
$dislikes = $row["dislikes"];
if ($like == "yes")
$likes++;
if ($like == "no")
$dislikes++;
$mysqli->query("UPDATE records SET likes = ".$likes." , dislikes = ".$dislikes." WHERE filename = '".$mysqli->real_escape_string($filename)."';");
}
else{
if($like=="yes")
$mysqli->query("INSERT INTO records VALUES('".$mysqli->real_escape_string($filename)."',1,0)");
else if($like=="no")
$mysqli->query("INSERT INTO records VALUES('".$mysqli->real_escape_string($filename)."',0,1)");
}
$mysqli->close();
?>