-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfavorite.php
45 lines (34 loc) · 939 Bytes
/
addfavorite.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
<?php
require_once('dbconnect.php');
$sessionId = session_id();
if(empty($sessionId)) session_start();
if ($_POST)
{
$videoid = $_POST["videoid"];
$email;
if (isset($_COOKIE['loggedIn'])) {
$email = $_COOKIE['loggedIn'];
}
if (isset($_SESSION['favorites'])) {
$fav = $_SESSION['favorites'];
$array = explode(" ", $_SESSION['favorites']);
if (!in_array($videoid, $array))
{
$favorites = $fav . " " . $videoid;
$_SESSION['favorites'] = $favorites;
$query = "UPDATE session SET favorites=\"$favorites\" WHERE email=\"$email\"";
mysqli_query($conn, $query);
echo "Successfully added into favorites";
}
else {
echo "Already added into favorites";
}
}
else {
$_SESSION['favorites'] = $videoid;
$query = "INSERT INTO session(email,favorites) VALUES(\"$email\",\"$videoid\")";
mysqli_query($conn, $query);
echo "Successfully added into favorites";
}
}
?>