Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Last active August 31, 2018 20:45
Show Gist options
  • Save IhwanID/0a6e8d184ed12c0d0f4fd188319953cb to your computer and use it in GitHub Desktop.
Save IhwanID/0a6e8d184ed12c0d0f4fd188319953cb to your computer and use it in GitHub Desktop.
sample code of create post in workshop blog php
<?php
//session_start();
//if(! isset($_SESSION['loggedin']))
//exit('akses dilarang, silahkan login dulu');
include_once('config.php');
$judul = "Tambah Post";
$subjudul = "";
$url_banner = "assets/img/home-bg.jpg";
if(isset($_POST['submit'])){
$judul = $_POST['judul'];
$konten = $_POST['konten'];
$query = mysqli_query($mysqli, 'INSERT INTO posts (judul, konten) VALUES ("'.$judul.'" , "'.$konten.'")');
if($query){
header('Location: index.php');
}else{
$error = "Error : " . mysqli_error($mysqli);
}
}
?>
<?php include('header.php'); ?>
<!-- Main Content -->
<div class="container">
<form action="create_post.php" method="post">
<label >Judul Artikel</label>
<input type="text" name="judul" class="form-control">
<br>
<label>Isi Artikel</label>
<textarea name="konten" class="form-control"></textarea>
<hr>
<button type="submit" name="submit" value="submit">Submit Artikel</button>
</form>
</div>
<?php include('footer.php'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment