-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlikes.php
More file actions
62 lines (43 loc) · 1.53 KB
/
likes.php
File metadata and controls
62 lines (43 loc) · 1.53 KB
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
<?php
session_start();
$user_id = $_GET['user'];
$idpass = $_GET['id'];
$id = $_SESSION['id'];
//echo $id;
if(!isset($_SESSION['user'])){
echo '<script language="javascript">';
echo 'alert("What? Dude login first :P")';
echo '</script>';
header("Refresh: 1; url=login.php");
exit();
}
else {
$name = $_SESSION['user'];
//$_SESSION['liker'] = $idpass;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pdologin";
$tbname = "posts";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM $tbname WHERE id = :id");
$stmt->execute(['id' => $idpass]);
$query = $stmt->fetch(PDO::FETCH_ASSOC);
echo $query['title'];
$query['likes'] = $query['likes'] + 1;
$newlikes = $query['likes'];
$stmt1 = $conn->prepare("UPDATE $tbname SET likes = :likes WHERE id = :id");
$stmt1->execute(['likes' => $newlikes, 'id' => $idpass]);
header("Location:welcome.php");
}
catch(PDOException $e) {
echo '<script language="javascript">';
echo '$sql . "<br>" . $e->getMessage();';
echo '</script>';
header("Refresh: 1; url=welcome.php");
}
$conn = NULL;
}
?>