1. Db_berita.php
<?php
$sambung=mysql_connect("localhost","root","");
if ($sambung){
echo "Koneksi berhasil";
}else{
echo "Koneksi gagal";
}
$query="CREATE DATABASE IF NOT EXISTS beritaonline";
if (mysql_query("$query")) {
print ("<br>Database sukses dibuat <br>");
mysql_select_db("beritaonline") or die(mysql_error());
} else {
print ("<br>Database gagal dibuat: <br><br>". mysql_error ());
}
//========================================================================
$tb_kategori="CREATE TABLE kategori (
id_kategori varchar(5) NOT NULL,
nm_kategori varchar(40) NOT NULL,
deskrpisi varchar(100) NOT NULL,
PRIMARY KEY (id_kategori))";
//========================================================================
if (mysql_query("$tb_kategori")) {
echo "<br>1- SUKSES tabel Kategori berhasil dibuat";
}else{
echo "<br>1- GAGAL tabel kategori gagal dibuat";
}
$tb_berita="CREATE TABLE berita(
id_berita varchar(5) NOT NULL,
id_kategori varchar(5) NOT NULL,
judul varchar(100) NOT NULL,
headline text not null,
isi_berita text not null,
pengirim varchar(20),
tanggal datetime not null default '0000-00-00 00:00:00',
PRIMARY KEY (id_berita))";
//========================================================================
if (mysql_query("$tb_berita")) {
echo "<br>2- SUKSES tabel Berita berhasil dibuat";
}else{
echo "<br>2- GAGAL tabel Berita gagal dibuat";
}
//========================================================================
?>
2. Koneksi.php
<?
$koneksi=mysql_connect("localhost","root","");
if($koneksi){
$bukadb=mysql_select_db("beritaonline");
if(!bukadb){
echo "database tidak dapat diaktifkan";
}
}else{
echo "Koneksi ke server mysql Gagal terhubung";
}
?>
3. Input_kategori.php
<?
include "koneksi.php";
//Simpan Berita
if(isset($_POST['input'])) {
$xid_kategori=$_POST['id_kategori'];
$xnm_kategori=$_POST['nm_kategori'];
$xdeskripsi =$_POST['deskripsi'];
//$query_simpan="insert into kategori VALUES ('$xid_kategori','$xnm_kategori','$xdeskripsi')";
$query_simpan="INSERT INTO kategori VALUES('$xid_kategori','$xnm_kategori','$xdeskripsi')";
$proses_simpan=mysql_query($query_simpan);
// uji proses simpan data ke tabel
if ($preses_simpan){
echo " data kategori sudah tersimpan ";
}else{
echo "data kategori gagal tersimpan ";
}
}
?>
<html>
<head>
<title> INPUT KATEGORI BERITA </title>
</head>
<body>
<form method="POST" name ="input" action="">
<table>
<tr>
<td> ID Kategori </td>
<td>: <input type="text" name="id_kategori" size ="10"></td>
</tr>
<tr>
<td> Nama Kategori </td>
<td>: <input type="text" name="nm_kategori" size ="40"></td>
</tr>
<tr>
<td> Deskripsi </td>
<td>: <input type="text" name="deskripsi" size ="40"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="input" value="input kategori">  
<input type="reset" name="reset" value="Batal">
</td>
</tr>
</table>
</body>
</html>
0 komentar:
Posting Komentar