-
Notifications
You must be signed in to change notification settings - Fork 1
/
favorites.php
executable file
·66 lines (65 loc) · 3.41 KB
/
favorites.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
57
58
59
60
61
62
63
64
65
66
<?php
session_start();
require_once('database.php');
if(@$_GET['user_id']){
$user_id=$_GET['user_id'];
$post_id=$_GET['post_id'];
$table=$_GET['table'];
if($_SESSION['id']==$user_id && @$_SESSION['ip']==$_SERVER['REMOTE_ADDR']){
$db=new database();
$db->open_connection();
if($table=='delete'){
$s="DELETE FROM favorites WHERE id='$post_id'";
$db->query($s);
echo '
<script type="text/javascript">
function errorhide(){
$("#error_message").hide();
}
</script>
<div id="error_message"><br/><br/>Deleted from favorites.<br/><br/><a href="index.php?do=favorites" onclick="errorhide()">Close</a><br/></div>';
}
else{
$s="SELECT * FROM favorites WHERE user_id='$user_id' AND post_id='$post_id' AND type='$table'";
$r=mysql_query($s);
if(mysql_num_rows($r)>0){
echo '
<script type="text/javascript">
function errorhide(){
$("#error_message").hide();
}
</script>
<div id="error_message"><br/><br/>You have this add in your favorites.<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
}
else{
$t=addslashes($table);
$p=addslashes($post_id);
$s="SELECT * FROM ".$t." WHERE ID='$p'";
list($result,$a)=$db->query($s);
if(mysql_num_rows($result)>0){
$db->open_connection();
$sql="INSERT INTO favorites VALUES ('null','$user_id','$p','$t')";
if(mysql_query($sql)){
echo '
<script type="text/javascript">
function errorhide(){
$("#error_message").hide();
}
</script>
<div id="error_message"><br/><br/>Added to favorites.<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
}
else{
echo '
<script type="text/javascript">
function errorhide(){
$("#error_message").hide();
}
</script>
<div id="error_message"><br/><br/>An error occurred.<br/><br/><a href="#" onclick="errorhide()">Close</a><br/></div>';
}
}
}
}
}
}
?>