-
Notifications
You must be signed in to change notification settings - Fork 0
/
favourites.php
32 lines (22 loc) · 843 Bytes
/
favourites.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
<?php
session_start();
if (isset($_POST['addToFavBtn'])) {
if ( isset($_SESSION['user'])) {
include 'dbConfig.php';
$sth = $dbh -> prepare('SELECT * FROM favourites WHERE user = ? AND trip = ?')
$sth -> execute([$_SESSION['user'], $_GET['id']])
if ($sth -> fetch(PDO:FETCH_OBJ)) {
$sth = $dbh -> prepare('DELETE FROM favourites WHERE user = ? AND trip = ?')
$sth -> execute([$_SESSION['user'], $_GET['id']])
}
else {
$sth = $dbh -> prepare('INSERT INTO favourites (user, trip) VALUES (?,?)')
$sth -> execute([$_SESSION['user'], $_GET['id']])
}
header("Location: " . $_GET['href']);
}
else {
$_SESSION['errorLog'] = 'login please!';
header("Location: " . $_GET['href']);
}
}