forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit-post-sql.php
More file actions
32 lines (24 loc) · 877 Bytes
/
edit-post-sql.php
File metadata and controls
32 lines (24 loc) · 877 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
32
<?php
// Create connection
$con=mysqli_connect("localhost","root","","blog_content");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// 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']);
$id = mysqli_real_escape_string($con, $_POST['id']);
//parsing tanggal dari html ke mysql
list($hari, $bulan, $tahun) = explode("/", $tanggal);
$tanggal = $tahun."-".$bulan."-".$hari;
$sql = "UPDATE `blog` SET `ID`='$id' ,`TANGGAL`='$tanggal',`JUDUL`='$judul',
`ISI`='$konten' WHERE `ID`=$id";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
header("Location: index.php"); /* Redirect browser */
exit();
?>