26 Des 2012

php web













delete.php

<?php
include "koneksi.php";
$id = $_GET['id'];
mysql_query("delete from user where id_user=$id");
header( 'Location: tampil.php' ) ;
?>

simpan.php
<?php
include "koneksi.php";
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
$email = $_POST['email'];
mysql_query("insert into user (`username`,`password`,`email`) values('$username','$password','$email')");
header( 'Location: tampil.php' ) ;
?>

koneksi.php

<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "terserah";

//koneksi ke mysql

mysql_connect($host,$username,$password) or die("koneksi gagal");

//select database

mysql_select_db($database);
?>

admin.php p7
<?php
session_start();
if(!$_SESSION['login_status']) echo '<script > alert("anda harus login terlebih dahulu"); location.href="login.php";</script>';
include 'tampil.php';
?>

login.php
<?php
session_start();
 if( $_SESSION['login_status'] ==true) echo '<script> alert("anda haru login terlebih dahulu"); location.href="admin.php";</script>';?>
<form method="post" action="proseslogin.php">
username : <input type="text" name="username"><br>
password : <input type="password" name="password"><br>
<input type="submit" value="Log in">
</form>

tampil.php
<form method="post" action="logout.php">
<?php
include "koneksi.php";

$hasil = mysql_query("select * from user");
echo "<table border='1'>
<tr>
<th>USERNAME</th>
<th>PASSWORD</th>
<th>EMAIL</th>
<th> </th>
</tr>";

while($row = mysql_fetch_array($hasil))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td> <a href='delete.php?id= ".$row['id_user']."'>Buang ke tempat sampah</a> </td>";
  echo "</tr>";
  }
echo "</table>";
?>
<input type="submit" value="Log out">
</form>

logout.php
<?php
session_start();
session_destroy();
header( 'Location: login.php' ) ;
?>

list_berita.php
<?php
include 'koneksi.php';
session_start();
if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login terlebih dahulu"); location.href="login.php";</script>';

if(isset($_POST['judul']) && isset ($_POST['isi'])):
$date = date('Y-m-d');
$status = mysql_query("INSERT INTO berita (`judul`, `isi`, `tanggal`) VALUES ('$_POST[judul]', '$_POST[isi]', '".$date."')");
if($status): echo '<script>location.href="list_berita.php";</script>';
else : echo '<script>alert("gagal"); location.href="list_berita.php"; </script>'; endif;
endif;
?>

<?php if (isset($_GET['action']) && $_GET['action'] == 'tambah') :?>
<form method="post" action="list_berita.php">
<label>judul</label><input type="text" name="judul"><br>
<label>konten</label><textarea name="isi"></textarea><br>
<input type="submit">
</form>
<?php else: ?>
<a href="?action=tambah"> Tambah berita </a>
<table>
<tr>
<td>NO</td>
<td>Judul</td>
<td>isi</td>
<td>aksi</td>
</tr>
<?php $i=1; ?>
<?php $result = mysql_query('SELECT * FROM berita'); ?>
<?php while($row = mysql_fetch_object($result)):?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row->judul; ?></td>
<td><?php echo $row->isi; ?></td>
<td>
<a href="hapus_berita.php?id_berita=<?php echo $row->id_berita?>" onclick="return confirm ('ciyus ?? ')">hapus</a>
<a href="edit_berita.php?id_berita=<?php echo $row->id_berita?>">edit</a>
</td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>

hapus_berita.php
<?php
include 'koneksi.php';
session_start();
if(isset($_GET['id_berita'])):
$status = mysql_query("DELETE FROM berita where id_berita = ".$_GET['id_berita']);
if($status):echo '<script> loaction.href="list_berita.php";</script>';
else : echo '<script>alert("gagal");location.href="list_berita.php";</script>';endif;
endif;
?>

edit_berita.php

<?php
include 'koneksi.php';
session_start();
if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login dahulu");location.href="login.php";</script>';

if(isset($_POST['id_berita']) && isset($_POST['judul']) && isset($_POST['isi'])):
$status = mysql_query("UPDATE berita SET `judul` = '$_POST[judul]', `isi` = '$_POST[isi]' WHERE id_berita=$_POST[id_berita]  ");
if($status): echo '<script>location.href="list_berita.php";</script>';
else : echo '<script>alert("gagal"); location.href="list_berita.php"; </script>'; endif;
endif;
if(isset($_GET['id_berita'])):
$result = mysql_query("SELECT * FROM berita where id_berita=".$_GET['id_berita']);
$berita = mysql_fetch_object($result);
?>
<form method="post" action="edit_berita.php">
<input type="hidden" name="id_berita" value="<?php echo $berita->id_berita;?>">
<label>judul</label><input type="text" name="judul" value="<?php echo $berita->judul;?>"><br>
<label>konten</label><textarea name="isi"><?php echo $berita->isi;?></textarea><br>
<input type="submit" value="simpan">
</form>
<?php endif; ?>

index.php
<a href="?act=tambah">tambah berita</a>
<?php
include 'koneksi.php';
if(isset($_GET['act'])=='tambah'):?>
<form action="?atc=insert" method="post">
Judul : <input type="text" name="judul"/><br>
Isi : <textarea name="isi"></textarea><br>
<input type="submit" name="sumbit" value="tambah berita"/>
</form>
<?php
endif;
if($_GET['atc']=='insert'):
$tanggal = date('y-m-d');
mysql_query("INSERT INTO beritaa(`judul`,`isi`,`tanggal`) 
VALUES ('$_POST[judul]','$_POST[isi]','$tanggal');");
endif;
?>
<table border="1">
<tr>
<td>no</td>
<td>judul</td>
<td>isi</td>
<td>tanggal</td>
<td>aksi</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM beritaa");
$no = 1;
while($r = mysql_fetch_object($result)):?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $r->judul;?></td>
<td><?php echo $r->isi;?></td>
<td><?php echo $r->tanggal;?></td>
<td><a href="?act=edit&id_berita=<?php echo $r->id_berita?>">edit</a> | <a href="?act=delet">delet</a></td>
</tr>
<?php
endwhile;
?>
</table>
<?php
if($_GET['act']=='edit'):
$id_berita=$_GET['id_berita'];
$result = mysql_query("SELECT * FROM beritaa where id_berita='$id_berita'");
$no = 1;
$r = mysql_fetch_object($result);
?>
<form action="?atc=postedit" method="post">
Judul : <input type="text" name="judul" value="<?php echo $r->judul?>"/><br>
Isi : <textarea name="isi" ><?php echo $r->isi?></textarea><br>
<input type="submit" name="sumbit" value="tambah berita"/>
</form>
<?php
endif;
?>

dashboard.php
<a href="?act=tambah">tambah berita</a>
<?php
include 'koneksi.php';
if(isset($_GET['act'])=='tambah'):?>
<form action="?atc=insert" method="post">
Judul : <input type="text" name="judul"/><br>
Isi : <textarea name="isi"></textarea><br>
<input type="submit" name="sumbit" value="tambah berita"/>
</form>
<?php
endif;
if($_GET['atc']=='insert'):
$tanggal = date('y-m-d');
mysql_query("INSERT INTO beritaa(`judul`,`isi`,`tanggal`) 
VALUES ('$_POST[judul]','$_POST[isi]','$tanggal');");
endif;
?>
<table border="1">
<tr>
<td>no</td>
<td>judul</td>
<td>isi</td>
<td>tanggal</td>
<td>aksi</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM beritaa");
$no = 1;
while($r = mysql_fetch_object($result)):?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $r->judul;?></td>
<td><?php echo $r->isi;?></td>
<td><?php echo $r->tanggal;?></td>
<td><a href="?act=edit&id_berita=<?php echo $r->id_berita?>">edit</a> | <a href="?act=delet&id_berita=<?php echo $r->id_berita?>">delet</a></td>
</tr>
<?php
endwhile;
?>
</table>
<?php
if($_GET['act']=='edit'):
$id_berita=$_GET['id_berita'];
$result = mysql_query("SELECT * FROM beritaa where id_berita='$id_berita'");
$no = 1;
$r = mysql_fetch_object($result);
?>
<form action="?atc=postedit&id_berita=<?php echo $r->id_berita?>" method="post">
Judul : <input type="text" name="judul" value="<?php echo $r->judul?>"/><br>
Isi : <textarea name="isi" ><?php echo $r->isi?></textarea><br>
<input type="submit" name="sumbit" value="tambah berita"/>
</form>
<?php
endif;
if($_GET['act']=='postedit'):
if(isset($_POST['id_berita']) && isset($_POST['judul']) && isset($_POST['isi'])):
$status = mysql_query("UPDATE berita SET `judul` = '$_POST[judul]', `isi` = '$_POST[isi]' WHERE id_berita=$_POST[id_berita]  ");
if($status): echo '<script>location.href="list_berita.php";</script>';
else : echo '<script>alert("gagal"); location.href="list_berita.php"; </script>'; endif;
endif;
endif;
if($_GET['act']=='delet'):
$id_berita=$_GET['id_berita'];
$hasil = mysql_query("DELETE FROM beritaa WHERE id_berita = '$id_berita'");
echo "<script>alert('Berhasil Menghapus Data!');</script>";
echo "<script>location.href='admin.php'</script>";
?>
<?php
endif;
?>

proseslogin.php
<?php
include 'koneksi.php';
session_start();
if(isset($_POST['username']) && isset($_POST['password'])):
$query_count = mysql_query("select count(*) as jumlah from user where username='$_POST[username]' AND password=MD5('$_POST[password]')");
$result_count = mysql_fetch_object($query_count);
if($result_count->jumlah > 0):
$query = mysql_query("select * from user where username='$_POST[username]' AND password=MD5('$_POST[password]')");
$result = mysql_fetch_object($query);
$_SESSION['id_user'] = $result->id_user;
$_SESSION['login_status'] = true;
echo '<script> alert("sukses tos sik"); location.href="admin.php";</script>';
else:
'<script> alert("Username dan password yang anda masukkan salah"); location.href="login.php";</script>';
endif;
else:
'<script> alert("Username dan password harus diisi"); location.href="login.php";</script>';
endif;
?>admin.php p9

<?php
session_start();
if(!$_SESSION['login_status']) echo '<script>alert("anda harus login terlebih dahulu"); location.href="login.php";</script>';

include 'dashboard.php';

?>


home.php
<?php
include "koneksi.php";

$berita = mysql_query("SELECT * FROM berita");
while ($row = mysql_fetch_object($berita)):
echo "<h1>".$row->judul."</h1>";
echo "<small>".$row->tanggal."<small>";
echo "<p>".$row->isi."</p><br>";
echo "<hr>";

$komentar = mysql_query("SELECT * FROM komentar where id_berita = ".$row->id_berita);

while($komen = mysql_fetch_object($komentar)):
echo $komen->nama." : ";
echo "<i>".$komen->komentar."</i><br><br>";
endwhile;

echo "<hr>";
?>
<form method="post" action="post_komentar.php">
<input type="hidden" name="id_berita" value="<?php echo $row->id_berita ?>"></input>
nama : <input type="text" name="nama"></input><br>
email : <input type="email" name="email"></input><br>
url : <input type="text" name="url"></input><br>
komentar : <textarea name="komentar"></textarea><br>
<input type="submit" value="kirim">
</form>

<?php
endwhile;
?>


post_komentar.php

<?php
include "koneksi.php";

if(isset($_POST['komentar']) && isset($_POST['email']) && isset($_POST['nama'])):
$send = mysql_query("INSERT INTO komentar (`nama`, `email`, `url`, `komentar`, `id_berita`) 
VALUES ('$_POST[nama]', '$_POST[email]', '$_POST[url]', '$_POST[komentar]','$_POST[id_berita]')");
if($send):
echo '<script>location.href="home.php";</script>';
else : echo '<script>alert("gagal");location.href="home.php";</script>';
endif;
endif;

?>

Photobucket