-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-posts-crud.php
48 lines (40 loc) · 1.31 KB
/
api-posts-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
48
<?php
// echo $_POST['txtPostIdCrud'];
if(isset($_POST['txtBannedCrud']) && isset($_POST['txtPostIdCrud'])){
// 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
$postId = $_POST['txtPostIdCrud'];
// $newHeadline = $_POST['txtHeadlineCrud'];
$newBanned = $_POST['txtBannedCrud'];
// UPDATE THE DB WITH FORM DATA
try{
$sUpdate = $db->prepare( 'UPDATE posts SET banned = :newBanned WHERE id_posts = :postId' );
$sUpdate->bindValue( ':newBanned' , $newBanned );
$sUpdate->bindValue( ':postId' , $postId );
$sUpdate->execute();
}catch( PDOException $ex ){
echo $ex;
exit;
}
echo 'update done';
exit;
}else{
echo 'there was no data';
exit;
}
?>