Buat sendiri Website yuks,..
gampang kok, ga pelu pinter pinter amat untuk buat CMS, cukup sedikt pengetahuan tentang HTML, CSS style, PHP dan Query database
kali ini saya akan tunjukan bagaimana mudahnya membuat website menggunakan Teknologi PHP dan MySQL
Aplikasi PHP yang perlu dipelajari kali ini adalah
Variable, Include, Function, IF, Swicth dan header
Pada bagian MySQL adalah
mysql_connect, mysql_select_db, mysql_querry, mysql_fetch_array dan mysql_nums_row()
dan tentunya 4 perintah SQL, yaitu
Insert, Select, Update dan Delete
gampang kok, ga pelu pinter pinter amat untuk buat CMS, cukup sedikt pengetahuan tentang HTML, CSS style, PHP dan Query database
kali ini saya akan tunjukan bagaimana mudahnya membuat website menggunakan Teknologi PHP dan MySQL
Aplikasi PHP yang perlu dipelajari kali ini adalah
Variable, Include, Function, IF, Swicth dan header
Pada bagian MySQL adalah
mysql_connect, mysql_select_db, mysql_querry, mysql_fetch_array dan mysql_nums_row()
dan tentunya 4 perintah SQL, yaitu
Insert, Select, Update dan Delete
CMS yang akan kita buat ini memiliki dua sisi, user dan admin.
Okay,..kita mulai
Jalankan terlebih dahulu Xampp webserver dan siapkan Dreamweaver Web Editor
FILE AND FOLDER
Buat beberapa folder pada direktori berikut
Buat beberapa folder pada direktori berikut
C:/xampp/htdocs/lat1
C:/xampp/htdocs/lat1/admin
C:/xampp/htdocs/lat1/templates
C:/xampp/htdocs/lat1/templates/basic
C:/xampp/htdocs/lat1/admin
C:/xampp/htdocs/lat1/templates
C:/xampp/htdocs/lat1/templates/basic
DATABASE
Buat sebuah databse dengan nama lat1. Gunakan Phpmyadmin (http://localhost/phpmyadmin)
Buat sebuah databse dengan nama lat1. Gunakan Phpmyadmin (http://localhost/phpmyadmin)
CREATE TABLE IF NOT EXISTS halaman (
kode int(5) unsigned NOT NULL auto_increment,
menu varchar(50) DEFAULT '0' ,
isi varchar(255) ,
PRIMARY KEY (kode)
);
kode int(5) unsigned NOT NULL auto_increment,
menu varchar(50) DEFAULT '0' ,
isi varchar(255) ,
PRIMARY KEY (kode)
);
INSERT INTO halaman VALUES("1", "Home", "Isi Home");
INSERT INTO halaman VALUES("2", "About", "isi About");
INSERT INTO halaman VALUES("9", "Gallery", "Isi Gallery");
INSERT INTO halaman VALUES("13", "profile", "isi Profile");
INSERT INTO halaman VALUES("2", "About", "isi About");
INSERT INTO halaman VALUES("9", "Gallery", "Isi Gallery");
INSERT INTO halaman VALUES("13", "profile", "isi Profile");
ADMINISTRATOR
Simpan 7 file berikut kedalam folder admin (C:/xampp/htdocs/lat1/admin/)
Simpan 7 file berikut kedalam folder admin (C:/xampp/htdocs/lat1/admin/)
1.koneksi.php
<?
mysql_connect("localhost","root","");
mysql_select_db("lat1");
?>
mysql_connect("localhost","root","");
mysql_select_db("lat1");
?>
2. input.php
<?
echo "<b>Create Page</b><br><br>
<form action=insert.php method=post><table border=0>
<tr><td> menu:</td><td><input type=text name=menu></td></tr>
<tr><td> Isi:</td><td><textarea name=isi></textarea></td></tr>
<tr><td></td><td><input type=submit value=Tambah name=submit></td></tr>
</form></table>";
?>
echo "<b>Create Page</b><br><br>
<form action=insert.php method=post><table border=0>
<tr><td> menu:</td><td><input type=text name=menu></td></tr>
<tr><td> Isi:</td><td><textarea name=isi></textarea></td></tr>
<tr><td></td><td><input type=submit value=Tambah name=submit></td></tr>
</form></table>";
?>
3.insert.php
<?
include "koneksi.php";
$menu= $_POST['menu'];
$isi = $_POST['isi'];
$submit = $_POST['submit'];
if ($submit)
{$sql=mysql_query("select * from halaman where menu='$menu'");
if(($row=mysql_fetch_array($sql)) && ($menu==$row[menu]))
{ echo "<b>Sudah Ada</b><br> <a href=input.php>Ulangi</a>";
exit; }
else
{ $result=mysql_query("insert into halaman (menu, isi) values ('$menu', '$isi')");
if (!$result)
{ echo "Gagal <br> <a href=input.php>Ulangi</a>";}
}}
header("Location:index.php");
?>
include "koneksi.php";
$menu= $_POST['menu'];
$isi = $_POST['isi'];
$submit = $_POST['submit'];
if ($submit)
{$sql=mysql_query("select * from halaman where menu='$menu'");
if(($row=mysql_fetch_array($sql)) && ($menu==$row[menu]))
{ echo "<b>Sudah Ada</b><br> <a href=input.php>Ulangi</a>";
exit; }
else
{ $result=mysql_query("insert into halaman (menu, isi) values ('$menu', '$isi')");
if (!$result)
{ echo "Gagal <br> <a href=input.php>Ulangi</a>";}
}}
header("Location:index.php");
?>
4.index.php
<?
include "koneksi.php";
echo "<a href=input.php>Buat Isi Baru</a> <br><br>
<table border=0 cellspacing=1 cellpadding=3 bgcolor=black>
<tr bgcolor=white><td>Kode</td><td>Menu</td><td>Isi</td><td>Aksi</td></tr>";
$sql=mysql_query("SELECT * FROM halaman ");
while($row=mysql_fetch_array($sql))
{echo "<tr bgcolor=white> <td> $row[kode] </td> <td> $row[menu] </td> <td> $row[isi] </td>
<td><a href=edit.php?pilihmenu=$row[kode]>Edit</a> |
<a href=delete.php?pilihmenu=$row[kode]>Hapus</a></td>";}
echo "</tr></table>";
?>
include "koneksi.php";
echo "<a href=input.php>Buat Isi Baru</a> <br><br>
<table border=0 cellspacing=1 cellpadding=3 bgcolor=black>
<tr bgcolor=white><td>Kode</td><td>Menu</td><td>Isi</td><td>Aksi</td></tr>";
$sql=mysql_query("SELECT * FROM halaman ");
while($row=mysql_fetch_array($sql))
{echo "<tr bgcolor=white> <td> $row[kode] </td> <td> $row[menu] </td> <td> $row[isi] </td>
<td><a href=edit.php?pilihmenu=$row[kode]>Edit</a> |
<a href=delete.php?pilihmenu=$row[kode]>Hapus</a></td>";}
echo "</tr></table>";
?>
5.edit.php
<?
include "koneksi.php";
$pilihmenu=$_GET['pilihmenu'];
$menu=$_GET['menu'];
$isi=$_GET['isi'];
$sql=mysql_query("select * from halaman where kode='$pilihmenu'");
$row=mysql_fetch_array($sql);
include "koneksi.php";
$pilihmenu=$_GET['pilihmenu'];
$menu=$_GET['menu'];
$isi=$_GET['isi'];
$sql=mysql_query("select * from halaman where kode='$pilihmenu'");
$row=mysql_fetch_array($sql);
echo "<b>Edit <b><br>
<form action=update.php method=post>
<table border=0>
<tr><td>Menu</td><td><input type=text name=menu value= $row[menu]></td></tr>
<tr><td>Isi</td><td><textarea name=isi>$row[isi]</textarea></td></tr>
<tr><td><input type=hidden name=kode value=$pilihmenu></td>
<td><input type=submit value=Edit></td></tr>
</table>
</form>";
?>
<form action=update.php method=post>
<table border=0>
<tr><td>Menu</td><td><input type=text name=menu value= $row[menu]></td></tr>
<tr><td>Isi</td><td><textarea name=isi>$row[isi]</textarea></td></tr>
<tr><td><input type=hidden name=kode value=$pilihmenu></td>
<td><input type=submit value=Edit></td></tr>
</table>
</form>";
?>
6.update.php
<?
include "koneksi.php";
$pilihmenu=$_POST['pilihmenu'];
$kode=$_POST['kode'];
$menu=$_POST['menu'];
$isi=$_POST['isi'];
$sql=mysql_query("update halaman set menu='$menu', isi='$isi' where kode='$kode'");
header("Location:index.php");
?>
include "koneksi.php";
$pilihmenu=$_POST['pilihmenu'];
$kode=$_POST['kode'];
$menu=$_POST['menu'];
$isi=$_POST['isi'];
$sql=mysql_query("update halaman set menu='$menu', isi='$isi' where kode='$kode'");
header("Location:index.php");
?>
7.delete.php
<?
include "koneksi.php";
$pilihmenu=$_GET['pilihmenu'];
$sql=mysql_query("delete from halaman where kode='$pilihmenu'");
if (!$sql){echo "data gagal dihapus";}
header("Location:index.php");
?>
include "koneksi.php";
$pilihmenu=$_GET['pilihmenu'];
$sql=mysql_query("delete from halaman where kode='$pilihmenu'");
if (!$sql){echo "data gagal dihapus";}
header("Location:index.php");
?>
WEBSITE
Simpan file berikut kedalam folder lat1 (C:/xampp/htdocs/lat1/)
Simpan file berikut kedalam folder lat1 (C:/xampp/htdocs/lat1/)
1.index.php
<?php
include("admin/koneksi.php");
include("templates/basic/index.php");
include("admin/koneksi.php");
include("templates/basic/index.php");
function fmenu() {
$sql=mysql_query("select * from halaman");
while($menu=mysql_fetch_array($sql))
{echo "<a href=?pilihmenu=$menu[menu]>$menu[menu]</a> | ";}
}
$sql=mysql_query("select * from halaman");
while($menu=mysql_fetch_array($sql))
{echo "<a href=?pilihmenu=$menu[menu]>$menu[menu]</a> | ";}
}
function fisi() {
$pilihmenu=$_GET['pilihmenu'];
if($pilihmenu==""){
$sql=mysql_query("select * from halaman where (menu='Home')");
$row=mysql_fetch_array($sql);
}else{
$sql=mysql_query("select * from halaman where (menu='$pilihmenu')");
$row=mysql_fetch_array($sql);
}echo "$row[isi]"; }
?>
$pilihmenu=$_GET['pilihmenu'];
if($pilihmenu==""){
$sql=mysql_query("select * from halaman where (menu='Home')");
$row=mysql_fetch_array($sql);
}else{
$sql=mysql_query("select * from halaman where (menu='$pilihmenu')");
$row=mysql_fetch_array($sql);
}echo "$row[isi]"; }
?>
TEMPLATE
Simpan file berikut kedalam folder lat1 (C:/xampp/htdocs/lat1/templates/basic)
1.index.php
<html>
<head>
<title>Basic</title>
<link href="templates/basic/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="header">
<span class="logo">Dasar CMS</span> versi 1.0</div>
<div class="menu"><?php fmenu(); ?></div>
<div class="content"> <?php fisi(); ?></div>
<div class="footer">
Dasar CMS<br>
www.dasarcms.web.id <BR>
2008
</div>
</body>
</html>
<head>
<title>Basic</title>
<link href="templates/basic/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="header">
<span class="logo">Dasar CMS</span> versi 1.0</div>
<div class="menu"><?php fmenu(); ?></div>
<div class="content"> <?php fisi(); ?></div>
<div class="footer">
Dasar CMS<br>
www.dasarcms.web.id <BR>
2008
</div>
</body>
</html>
2.style.css
body {
text-align: center;
padding: 16;
background-color: #0099CC;
}
a, a:link, a:active {
color: #FFFFFF;
}
a:visited, a:hover, a:focus {
color: #FFFFFF;
border: none;
outline: none;
}
.header {
width: 750px;
height: 75px;
background-color: #666666;
}
.menu {
text-align: center;
height: 25px;
width: 750px;
background-color: #000000;
}
.content {
text-align: left;
width: 730px;
background-color: #FFFFFF;
padding-left: 20px;
}
.footer {
width: 700px;
height: 60px;
background-color: #000000;
padding-left: 50px;
}
.logo {
font-size: 36px;
color: #FFFFFF;
}
text-align: center;
padding: 16;
background-color: #0099CC;
}
a, a:link, a:active {
color: #FFFFFF;
}
a:visited, a:hover, a:focus {
color: #FFFFFF;
border: none;
outline: none;
}
.header {
width: 750px;
height: 75px;
background-color: #666666;
}
.menu {
text-align: center;
height: 25px;
width: 750px;
background-color: #000000;
}
.content {
text-align: left;
width: 730px;
background-color: #FFFFFF;
padding-left: 20px;
}
.footer {
width: 700px;
height: 60px;
background-color: #000000;
padding-left: 50px;
}
.logo {
font-size: 36px;
color: #FFFFFF;
}