-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_mark.php~
36 lines (35 loc) · 1.08 KB
/
delete_mark.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
<?php
include('connect_db.php');
session_start();
$post_id = $_GET['id'];
$user_id = $_SESSION['profil_id'];
$sql = "SELECT mark FROM vote WHERE user_id=:user_id AND post_id=:post_id";
$STH = $DBH->prepare($sql);
$STH->bindValue(':user_id',$_SESSION['profil_id']);
$STH->bindValue(':post_id',$post_id);
$STH->execute();
$row = $STH->fetch();
$mark=$row['mark'];
echo $mark ; exit;
$sql = "DELETE FROM vote WHERE post_id= :post_id AND user_id= :user_id";
$STH = $DBH->prepare($sql);
$STH->bindValue(':user_id',$user_id);
$STH->bindValue(':post_id',$post_id);
$STH->execute();
$sql = "SELECT * FROM post WHERE id =:post_id";
$STH = $DBH->prepare($sql);
$STH->bindValue(':post_id',$post_id);
$STH->execute();
$row = $STH->fetch(PDO::FETCH_ASSOC);
$sum = $row['sum'];
$count = $row['count'];
$sum = $sum - $mark;
$count = $count - 1;
$sql = "UPDATE post SET sum = :sum, count= :count WHERE id = :post_id ";
$STH = $DBH->prepare($sql);
$STH->bindValue(':post_id',$post_id);
$STH->bindValue(':sum',$sum);
$STH->bindValue(':count',$count);
$STH->execute();
header('Location:'.$_SERVER['HTTP_REFERER']);
?>