forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_article.php
More file actions
33 lines (30 loc) · 1.32 KB
/
make_article.php
File metadata and controls
33 lines (30 loc) · 1.32 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
<?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($_POST['Judul']) && isset($_POST['Tanggal']) && isset($_POST['Konten'])){
$insertArticleQuery = "INSERT INTO article (article_title, article_date, article_content) VALUES (:title,:date,:content)";
$changedDate = strtotime(trim($_POST['Tanggal']));
$changedDateFormat = date("Y-m-d", $changedDate);
$articleHandler = $databaseHandler->prepare($insertArticleQuery);
$articleHandler->bindParam(':title',$_POST['Judul'],PDO::PARAM_STR,50);
$articleHandler->bindParam(':date',$changedDateFormat);
$articleHandler->bindParam(':content',$_POST['Konten'],PDO::PARAM_STR,5000);
$articleHandler->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);
}
?>