forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_post.php
38 lines (29 loc) · 816 Bytes
/
new_post.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
<!DOCTYPE html>
<html>
<body>
<?php
$Judul = $_POST["Judul"];
$Tanggal = $_POST["Tanggal"];
$Konten = $_POST["Konten"];
$con=mysqli_connect("localhost", "root", "", "SimpleBlog");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
echo "<br>";
}
// Insert into Posts
// escape variables for security
$Judul = mysqli_real_escape_string($con, $_POST['Judul']);
$Tanggal = mysqli_real_escape_string($con, $_POST['Tanggal']);
$Konten = mysqli_real_escape_string($con, $_POST['Konten']);
$sql="INSERT INTO Posts (Judul, Tanggal, Konten)
VALUES ('$Judul', '$Tanggal', '$Konten')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
echo "<br>";
mysqli_close($con);
header("location: index.php");
?>
</body>