-
Notifications
You must be signed in to change notification settings - Fork 1
/
like.php
42 lines (25 loc) · 1.06 KB
/
like.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
<?php
session_start();
require_once('configuration.php');
$artworkid = $_SESSION["artworkID"];
if(empty($_SESSION['userID'])){
$_SESSION['no-session'] = "Login first";
header("Location: individualartwork.php?uid=".$artworkID);
exit();
}
$userID = $_SESSION["userID"];
$checkSql = "SELECT * FROM `like` WHERE artworkID = $artworkid AND userID = $userID";
$result = $conn->query($checkSql);
if($result->num_rows > 0){
$sql = "UPDATE artworklikes SET numLikes = numLikes - 1 where artworkID = $artworkid;";
$conn->query($sql);
$sql_del = "DELETE FROM `like` WHERE artworkID = $artworkid AND userID = $userID;";
$conn->query($sql_del);
} else {
$sql_ins = "INSERT INTO `like` values($artworkid,$userID)";
$conn->query($sql_ins);
$sql_like = "UPDATE artworklikes SET numLikes = numLikes + 1 where artworkID = $artworkid";
$conn->query($sql_like);
}
header("Location: individualartwork.php?uid=".$artworkid);
?>