-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlike.php
74 lines (65 loc) · 2.55 KB
/
like.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
67
68
69
70
71
72
73
74
<?php
// session_start();
require 'connection.php';
// $idi = $_SESSION['id'];
// $idi = $_GET['id'];
$id_article = $_POST['id_article'];
echo $id_article = $_POST['id_article'];
// echo $idi = $_SESSION['id'];
$idi = $_COOKIE['login'] ;
echo $idi = $_COOKIE['login'] ;
// $sql = 'SELECT *
// FROM $usertable
// WHERE PartNumber = $partid';
//
// $result = mysqli_query($con, $sql);
// $row = mysqli_fetch_assoc($result);
if($_POST['like'])
{
if($idi=='')
{
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
else {
$q = mysqli_query($connection, "SELECT * FROM likes WHERE login_user='$idi' AND id_article=$id_article");
$r = mysqli_fetch_assoc($q);
// $q = mysql_query("SELECT * FROM likes WHERE id_user='$id' AND id_article='$id_article'", $db);
// $r = mysql_fetch_array($q);
if(($r['id']) == 0 OR $q == false)
{
$q2 = mysqli_query($connection, "INSERT INTO likes SET login_user = '$idi', id_article=$id_article");
// $q2 = mysql_query("INSERT INTO likes SET id_user = '$id', id_article='$id_article' ", $db);
if($q2 == true)
{
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
}
else {
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
}
}
if($_POST['dislike'])
{
if($idi=='')
{
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
else {
$q = mysqli_query($connection, "SELECT * FROM likes WHERE login_user = '$idi' AND id_article=$id_article");
$r = mysqli_fetch_assoc($q);
if(($r['id']) == 1 OR $q == true)
{
$q2 = mysqli_query($connection, "DELETE FROM likes WHERE login_user = '$idi' AND id_article=$id_article ");
if($q2 == true)
{
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
}
else {
echo "<html><head><meta http-equiv='Refresh' content='0; URL=/news.php?id=$id_article'></head></html>";
}
}
}
?>
<!-- <script>document.location.href="news.php"</script> -->