-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpin_idea.php
56 lines (43 loc) · 1.37 KB
/
pin_idea.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
53
54
55
56
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connections.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
$user = $_SESSION['email'];
$tagToPin = $_GET['pintag'];
$action = $_GET['action'];
$pinnedResult = mysql_query("SELECT * FROM pinned WHERE user='{$user}' ORDER BY pinned ASC", $connection);
if(!$pinnedResult){
die("Database query failed: " . mysql_error());
}
$pinnedTags = array();
while ($pinnedRow = mysql_fetch_array($pinnedResult)){
$pinnedTagRow = explode(",", $pinnedRow[2]);
foreach($pinnedTagRow as $eachRowPinnedTag){
$eachRowPinnedTag = trim($eachRowPinnedTag);
if($eachRowPinnedTag!=""){array_push($pinnedTags, $eachRowPinnedTag);}
}
}
if($action == 'pin'){
array_push($pinnedTags, $tagToPin);
$isPinned = 1;
}
elseif ($action == 'unpin'){
if(($key = array_search($tagToPin, $pinnedTags)) !== false) {
unset($pinnedTags[$key]);
}
$isPinned = 0;
}
$finalPinnedList = '';
foreach($pinnedTags as $textTag){
$finalPinnedList .= $textTag.',';
}
$updateQuery = "UPDATE pinned SET pinned='{$finalPinnedList}' WHERE user='{$user}'";
if (mysql_query($updateQuery, $connection)) {
header("Location: tags.php?sub=successful&isPinned=$isPinned");
exit;
} else {
header("Location: tags.php?sub=booboo&isPinned=$isPinned");
exit;
}
?>
<?php mysql_close($connection); ?>