-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-comments-crud.php
47 lines (39 loc) · 1.32 KB
/
api-comments-crud.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
<?php
// echo $_POST['txtPostIdCrud'];
if(isset($_POST['txtBannedCrudComments']) && isset($_POST['txtCommentsIdCrud'])){
// TOKENS
session_start();
// a token was created if the real person wanted to do this - does it match what we got?
if(!isset($_SESSION['token']) || !isset($_POST['activityToken'])){
//echo 'The token is not set';
header('location: ups.php');
exit;
}else{
// if there is a token, compare it to the one we got from the form
if (hash('sha256', $_SESSION['token']) != $_POST['activityToken']){
// redirect to UPS THIS WASN'T SUPPOSED TO HAPPEN page
header('location: ups.php');
exit;
}
}
require('controllers/database.php');
// SAVE DATA FROM FORM
$commentsId = $_POST['txtCommentsIdCrud'];
$newBanned = $_POST['txtBannedCrudComments'];
// UPDATE THE DB WITH FORM DATA
try{
$sUpdate = $db->prepare( 'UPDATE comments SET banned = :newBanned WHERE id_comments = :commentsId' );
$sUpdate->bindValue( ':newBanned' , $newBanned );
$sUpdate->bindValue( ':commentsId' , $commentsId );
$sUpdate->execute();
}catch( PDOException $ex ){
echo $ex;
exit;
}
echo 'update done';
exit;
}else{
echo 'there was no data';
exit;
}
?>