-
Notifications
You must be signed in to change notification settings - Fork 0
/
votedown.php
44 lines (38 loc) · 1017 Bytes
/
votedown.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
<?php
/**
* Created by PhpStorm.
* User: lukaszsnopkiewicz
* Date: 10/03/2018
* Time: 23:50
*/
header("Access-Control-Allow-Origin: *");
/**
* @var $servername
* @var $username
* @var $password
* @var $dbname
*/
extract(parse_ini_file('config.ini'));
if (
!(isset($_POST['page_to_paper_id']) || strlen($_POST['page_to_paper_id']) < 1)
|| (!isset($_POST['vote_count']) || !is_numeric($_POST['vote_count']))
) {
echo 'missing param';
exit;
}
$pageToPaperId = $_POST['page_to_paper_id'];
$voteCount = $_POST['vote_count'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$voteCount--;
if ($voteCount > 1) {
$sql = "UPDATE page_to_paper SET vote_count = '$voteCount' WHERE id = '$pageToPaperId'";
$result = $conn->query($sql);
} else {
$sql = "DELETE FROM page_to_paper WHERE id = '$pageToPaperId'";
$result = $conn->query($sql);
}