LOADING . . .
Selamat malam, tak terasa sudah sampai di part 6 dari seri Membuat Website Professional dengan PHP & MySql. Sebelumnya coba dilihat dulu posting terkait tentang tutorial ini:
Pada seri ke 6 ini, saatnya anda membuat manajemen Halaman, dimana nantinya akan meng-integrasikannya dengan tinyMCE. Nah apalagi itu TinyMCE? TinyMCE adalah HTML WYSIWYG editor, sehingga untuk mengetikkan teks menambah huruf tebal, miring, dan yang lainnya menjadi sangat mudah, dan hasilnya bila disimpan kedalam database otomatis dalam format tag html, sehingga memudahkan membantu dalam mengedit kalimat. Jadi untuk membuat posting seperti ini, anda akan dibantu untuk menebalkan font, mengatur ukuran dan lain sebagainya. Anda tidak perlu mengetik tab HTML Tulisan Tebal untuk menebalkan tulisan, TinyMCE yang akan melakukannya untuk anda.
Baca Juga: Bangkitnya Semangat UKM Indonesia
#1 Membuat Manajemen Halaman
Tambah Halaman
<?php
include "../config/koneksi.php";
session_start();
if($_SESSION['status'] !="login"){
header("location:../");
}
if(isset($_POST['judul'])){
$judul=htmlentities($_POST['judul']);
$deskripsi=$_POST['deskripsi'];
$status=$_POST['status'];
$sql=mysqli_query($koneksi, "INSERT INTO halaman (judul,deskripsi,status) VALUES ('$judul','$deskripsi','$status')");
if($sql){
header("location:halaman-list.php?pesan=Tambah halaman berhasil, selamat");
}else{
header("location:halaman-list.php?pesan=Tambah halaman gagal, coba lagi");
}
}else{
unset($_POST['judul']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<head>
<title>Suba Hospital | Tambah Halaman</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/sb-admin-2.min.css" rel="stylesheet">
<!-- Custom styles for this page -->
<link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<!-- Tiny MCE -->
[removed][removed]
[removed]
tinymce.init({
selector: 'textarea#exampleTextarea'
});
[removed]
</head>
<body id="page-top">
<!-- Page Wrapper -->
<?php include "sidebar.php"; ?>
<!-- Content Wrapper -->
<!-- Main Content -->
<?php include "topbar.php";?>
<!-- Begin Page Content -->
<!-- DataTales Example -->
Tambah Halaman
<?php
if(isset($_GET['pesan'])){
echo ' '.$_GET['pesan'].'';
}
?>
<form class="user" action="halaman-tambah.php" method="post">
<input type="text" name="judul" class="form-control" id="exampleInputJudul" placeholder="Judul Halaman...">
<textarea style="height:300px;" name="deskripsi" class="form-control" id="exampleTextarea" placeholder="Deskripsi halaman"></textarea>
<select style="width:200px;" class="form-control" id="exampleStatus" name="status">
</select>
<button style="width:200px; float:right;" class="btn btn-primary btn-block">
Publish
</button>
</form>
<!-- End Page Content -->
<!-- End Content Wrapper -->
<?php include "footer.php";?>
<!-- End Main Content -->
<!-- End Page Wrapper -->
<!-- Bootstrap core JavaScript-->
[removed][removed]
[removed][removed]
<!-- Core plugin JavaScript-->
[removed][removed]
<!-- Custom scripts for all pages-->
[removed][removed]
<!-- Page level plugins -->
[removed][removed]
[removed][removed]
<!-- Page level custom scripts -->
[removed][removed]
</body>
</html>
<!-- Tiny MCE -->
[removed][removed]
[removed]
tinymce.init({
selector: 'textarea#exampleTextarea'
});
[removed]
<form class="user" action="halaman-tambah.php" method="post">
<input type="text" name="judul" class="form-control" id="exampleInputJudul" placeholder="Judul Halaman...">
<textarea style="height:300px;" name="deskripsi" class="form-control" id="exampleTextarea" placeholder="Deskripsi halaman"></textarea>
<select style="width:200px;" class="form-control" id="exampleStatus" name="status">
</select>
<button style="width:200px; float:right;" class="btn btn-primary btn-block">
Publish
</button>
</form>
<form class="user" action="halaman-tambah.php" method="post">
jadi baris kode PHP dibawah ini, adalah "menangkap" apa yang form halaman tambah inputkan.
if(isset($_POST['judul'])){
$judul=htmlentities($_POST['judul']);
$deskripsi=$_POST['deskripsi'];
$status=$_POST['status'];
$sql=mysqli_query($koneksi, "INSERT INTO halaman (judul,deskripsi,status) VALUES ('$judul','$deskripsi','$status')");
if($sql){
header("location:halaman-list.php?pesan=Tambah halaman berhasil, selamat");
}else{
header("location:halaman-list.php?pesan=Tambah halaman gagal, coba lagi");
}
}else{
unset($_POST['judul']);
}
#2 Membuat Table Halaman
#3 Membuat List Halaman
<?php
include "../config/koneksi.php";
session_start();
if($_SESSION['status'] !="login"){
header("location:../");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<head>
<title>Suba Hospital | List Halaman</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/sb-admin-2.min.css" rel="stylesheet">
<!-- Custom styles for this page -->
<link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
</head>
<body id="page-top">
<!-- Page Wrapper -->
<?php include "sidebar.php"; ?>
<!-- Content Wrapper -->
<!-- Main Content -->
<?php include "topbar.php";?>
<!-- Begin Page Content -->
<!-- DataTales Example -->
List Halaman
<?php
if(isset($_GET['pesan'])){
echo ' '.$_GET['pesan'].'';
}
?>
<?php $sql = mysqli_query($koneksi, "select * from halaman");?>
<?php $no = 1; ?>
No
Judul
Publish
Action
No
Judul
Publish
Action
<?php while ($row=mysqli_fetch_array($sql)){ ?>
<?php echo $no; ?>
<?php echo $row['judul']?>
<?php if($row['status']==0){ ?>
Draft
<?php }else{ ?>
Published
<?php } ?>
Edit Hapus
<?php $no++; ?>
<?php } ?>
<!-- End Page Content -->
<!-- End Content Wrapper -->
<?php include "footer.php";?>
<!-- End Main Content -->
<!-- End Page Wrapper -->
<!-- Bootstrap core JavaScript-->
[removed][removed]
[removed][removed]
<!-- Core plugin JavaScript-->
[removed][removed]
<!-- Custom scripts for all pages-->
[removed][removed]
<!-- Page level plugins -->
[removed][removed]
[removed][removed]
<!-- Page level custom scripts -->
[removed][removed]
</body>
</html>
<?php $sql = mysqli_query($koneksi, "select * from halaman");?>
<?php $no = 1; ?>
No
Judul
Publish
Action
No
Judul
Publish
Action
<?php while ($row=mysqli_fetch_array($sql)){ ?>
<?php echo $no; ?>
<?php echo $row['judul']?>
<?php if($row['status']==0){ ?>
Draft
<?php }else{ ?>
Published
<?php } ?>
Edit Hapus
<?php $no++; ?>
<?php } ?>
#4 Membuat Halaman Edit
<?php
include "../config/koneksi.php";
session_start();
if($_SESSION['status'] !="login"){
header("location:../");
}
if(isset($_POST['judul'])){
$id=$_POST['id'];
$judul=htmlentities($_POST['judul']);
$deskripsi=$_POST['deskripsi'];
$status=$_POST['status'];
$update=mysqli_query($koneksi, "UPDATE halaman SET judul='$judul', deskripsi='$deskripsi', status='$status' WHERE id='$id'");
if($update){
header("location:halaman-list.php?pesan=Update halaman berhasil, selamat");
}else{
header("location:halaman-list.php?pesan=Update halaman gagal, coba lagi");
}
}else{
unset($_POST['judul']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<head>
<title>Suba Hospital | Tambah Halaman</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/sb-admin-2.min.css" rel="stylesheet">
<!-- Custom styles for this page -->
<link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<!-- Tiny MCE -->
[removed][removed]
[removed]
tinymce.init({
selector: 'textarea#exampleTextarea'
});
[removed]
</head>
<body id="page-top">
<!-- Page Wrapper -->
<?php include "sidebar.php"; ?>
<!-- Content Wrapper -->
<!-- Main Content -->
<?php include "topbar.php";?>
<!-- Begin Page Content -->
<!-- DataTales Example -->
Edit Halaman
<?php
if(isset($_GET['pesan'])){
echo ' '.$_GET['pesan'].'';
}
?>
<?php
$id = $_GET['id'];
$sqlhal = mysqli_query($koneksi, "select * from halaman WHERE id='$id'");
$rowhal = mysqli_fetch_array($sqlhal);
?>
<form class="user" action="halaman-edit.php" method="post">
<input type="text" name="judul" class="form-control" id="exampleInputJudul" value="<?php echo $rowhal['judul'];?>" placeholder="Judul Halaman...">
<textarea style="height:300px;" name="deskripsi" class="form-control" id="exampleTextarea" placeholder="Deskripsi halaman"><?php echo $rowhal['deskripsi'];?></textarea>
<select style="width:200px;" class="form-control" id="exampleStatus" name="status">
<?php if($rowhal['status']==0){ ?>
<?php }else{ ?>
<?php } ?>
</select>
<input type="hidden" name="id" value="<?php echo $rowhal['id']?>">
<button style="width:200px; float:right;" class="btn btn-primary btn-block">
Update
</button>
</form>
<!-- End Page Content -->
<!-- End Content Wrapper -->
<?php include "footer.php";?>
<!-- End Main Content -->
<!-- End Page Wrapper -->
<!-- Bootstrap core JavaScript-->
[removed][removed]
[removed][removed]
<!-- Core plugin JavaScript-->
[removed][removed]
<!-- Custom scripts for all pages-->
[removed][removed]
<!-- Page level plugins -->
[removed][removed]
[removed][removed]
<!-- Page level custom scripts -->
[removed][removed]
</body>
</html>
<?php
$id = $_GET['id'];
$sqlhal = mysqli_query($koneksi, "select * from halaman WHERE id='$id'");
$rowhal = mysqli_fetch_array($sqlhal);
?>
Baris kode ini anda memanfaatkan method GET ($_GET) pada PHP untuk mendapatkan id yang dikirim oleh button EDIT di Halaman List, dan kemudian memanfaatkan syntax MySQL "WHERE" agar data yang ditampilkan memiliki id yang sama. Dan ditampilkan value data di form Edit dengan <?php echo $rowhal['judul']; ?> .#5 Membuat Button Hapus Halaman
<?php
session_start();
include '../config/koneksi.php';
$id = $_GET['id'];
$sql = mysqli_query($koneksi, "DELETE FROM halaman WHERE id='$id'");
if($sql){
header("location:halaman-list.php?pesan=Berhasil, halaman sudah dihapus");
}else{
header("location:halaman-list.php?pesan=Gagal, coba lagi");
}
?>
Hapus
Sekian posting Membuat Website Professional dengan PHP MySql - PART #6 ini, file tutorial ini bisa anda Download Disini. Stay Strong & Healthy. Bye Bye
mantap.... the best