-
Notifications
You must be signed in to change notification settings - Fork 0
/
likes.php
52 lines (44 loc) · 1.32 KB
/
likes.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
48
49
50
51
52
<?php
session_start();
$serverStr = $_SESSION['currentServer'];
$loggedInAs = $_SESSION['currentId'];
$videoId = $_POST['videoId'];
if(empty($loggedInAs)){
header("Location:login.php");
exit;
}
$dbHost = 'leaguelights.c1armosbaqhq.ca-central-1.rds.amazonaws.com';
$dbUser = 'daniel';
$dbPass = 'dksk18rotorl';
$dbConn = 'mysql:host='.$dbHost.';dbname='.$serverStr.';charset=utf8mb4';
if(isset($_POST['submit'])){
try{
$conn = new \PDO( $dbConn,
$dbUser,
$dbPass,
array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => false
)
);
$handle = $conn->prepare("Select * from likes where videoId = ? and likedBy = ?");
$handle->bindParam(1, $videoId);
$handle->bindParam(2, $loggedInAs);
$handle->execute();
if($handle->rowCount()<1){
$like=$conn->prepare("INSERT INTO likes (likedBy, videoId) VALUES (?,?)");
$like->bindParam(1, $loggedInAs);
$like->bindParam(2, $videoId);
$like->execute();
}else{
$like=$conn->prepare("DELETE FROM likes where videoId = ? and likedBy = ?");
$like->bindParam(1, $videoId);
$like->bindParam(2, $loggedInAs);
$like->execute();
}
}catch(\PDOException $ex){
print($ex->getMessage());
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>