Selasa, 25 Desember 2012

php

Admin.php

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

Delete.php
<?php
include("koneksi.php");
$id=$_GET[id];

$query="delete from admin where id_user='$id'";
$exe=mysql_query($query);
if ($exe){
    echo "<script>alert('Data Berhasil Dihapus')
    location.replace('user.php')</script>";
}else{
    echo "<script>alert('Data Gagal Dihapus')
    location.replace('user.php')</script>";
}
?>

Edit_berita.php
<?php
session_start();
include"koneksi.php";

if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login dulu");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; ?>

Hapus_berita.php

<?php
session_start();
include"koneksi.php";

if(isset($_GET['id_berita'])):
    $status = mysql_query("delete from berita where id_berita=".$_GET['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;

?>

index.php

<form action="simpan.php" method="post">
<table>
    <tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password" name="password"></td>
    </tr>
    <tr>
        <td>Email</td>
        <td><input type="text" name="email"></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" value="Simpan"></td>
    </tr>
   
</table>
</form>

Koneksi.php
<?php
mysql_connect("localhost","root","") or die("gagal koneksi");
mysql_select_db("pwd");
?>

List_berita.php

<?php
session_start();
include "koneksi.php";
if(!$_SESSION['login_status'])
echo '<script>alert("anda harus login dulu");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" value="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; ?>

Login.php

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

logout.php

<?php
session_start();
unset($_SESSION['login_status']);
echo '<script>alert("anda sudah logout"); location.href="login.php";</script>';
?>

proses_login.php

<?php
include 'koneksi.php';

session_start();
if(isset($_POST['username'])&& isset($_POST['password'])):
    $query_count = mysql_query("select count(*) as jumlah from admin 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 admin 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 sok"); location.href="admin.php";</script>';
    else:
        echo '<script>alert("Username dan password yang anda masukan salah"); location.href="login.php";</script>';
    endif;
else:
    echo '<script>alert("Username dan Password harus di isi"); location.href="login.php";</script>';
endif;
       
?>

Simpan.php

<?php
include "koneksi.php";
$input = $_POST[password];
$password = md5($input);
$sql="INSERT INTO admin (username, password, email)
VALUES
('$_POST[username]','$password','$_POST[email]')";
mysql_query($sql);
header( 'Location: user.php' );
?>

User.php

<form method="post" action="logout.php">
<input type="submit" value="Log out">
</form>
<?php
include "koneksi.php";
$sql=mysql_query("select *from admin");

echo "<table border='1'>
<tr>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Keterangan</th>
</tr>";

while($row = mysql_fetch_array($sql))
  {
  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'] ."'>Delete</a></td>";
  echo "</tr>";
  }
echo "</table>";
?>
 <a href="index.php">Tambah lagi</a><br>





Tidak ada komentar:

Posting Komentar