forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_post_database.php
More file actions
31 lines (26 loc) · 908 Bytes
/
delete_post_database.php
File metadata and controls
31 lines (26 loc) · 908 Bytes
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
<?php
try{
#Connect to MySQL
$host = "localhost";
$dbname = "simple_blog";
$user = "root";
$pass = "";
$databaseHandler = new PDO("mysql:host=$host;dbname=$dbname;",$user,$pass);
$databaseHandler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
#Query
if(isset($_GET['delete_id'])){
$deleteArticleQuery = "DELETE FROM article WHERE article_id = :delete_id";
$queryHandler = $databaseHandler->prepare($deleteArticleQuery);
$queryHandler->bindParam(':delete_id',$_GET['delete_id'],PDO::PARAM_INT);
$queryHandler->execute();
}
#Close connection
$databaseHandler = null;
#Redirect
header("Location: index.php");
die();
}catch(PDOException $e){
echo "Sorry, there is a problem now. Please come again later";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
?>