Pages

Minggu, 21 Juni 2015

Tugas Praktikum 4 DASKOM



Database : db_praktikum, dengan nama tabel : tb_mhs

koneksi.php
<?php $server = "localhost";
            $uid = "root";
            $pwd = "";
            $db = "db_praktikum";
            $konek = mysql_connect($server, $uid, $pwd);
            $pilihdb = mysql_select_db($db, $konek); ?>
index.php
<html>
<center>
            <HR width=600 color="red">
            <h1>SELAMAT DATANG</h1>
            <HR width=600 color="red">
</center>
<center>
            <h3><a href="inputdata.php">1. INPUT DATA MAHASISWA</a></h3>
            <h3><a href="lihatdata.php">2. LIHAT DATA MAHASISWA</a></h3>
            <HR width=600 color="red">
</center>
</html>

inputdata.php

<html>
<head>
</head>
<body>
<center>
            <HR width=600 color="red">
            <h1>INPUTKAN DATA ANDA</h1>
            <HR width=600 color="red">
            <table><center>
                        <form name="input" action="datasimpan.php" method="POST">
                                    <tr>
                                    <td>NBI</td>
                                    <td><input type="text" name="nbi" ></td>
                                    </tr>
                                    <tr>
                                    <td>Nama</td>
                                    <td><input type="text" name="nama" ></td>
                                    </tr>
                                    <tr>
                                    <td>Kelas</td>
                                    <td><input type="text" name="kelas"></td>
                                    </tr>
                                    <tr>
                                    <td>Alamat</td>
                                    <td><input type="text" name="alamat" ></td>
                                    </tr>
                                    <tr>
                                    <td colspan=1 ></td>
                                    <td><input type="submit" value="simpan">
                                    <input type="reset"  name="reset" value="reset">
                                    </tr>
                        </from>
            </table>
                        <HR width=600 color="red">
</center>
</body>
</html>


datasimpan.php
<?php
include "koneksi.php";
$nbi=$_POST["nbi"];
$nama=$_POST["nama"];
$kelas=$_POST["kelas"];
$alamat=$_POST["alamat"];
$sql="INSERT INTO tb_mhs VALUES ('$nbi', '$nama', '$kelas', '$alamat')";
mysql_query($sql);
header("location:lihatdata.php"); 
?>

lihatdata.php
<html>
<center>
            <HR width=600 color="red">
            <h1>DATA NAMA PRAKTIKUM</h1>
            <HR width=600 color="red">
</center>
<center>
            <table border="3">
                        <tr>
                        <th>NBI</th>
                        <th>NAMA</th>
                        <th>KELAS</th>
                        <th>ALAMAT</th>
                        <th>EKSEKUSI</th>
                        </tr>    
            <?php  include "koneksi.php";                      
                        $sql="SELECT * FROM tb_mhs";
                        $dta=mysql_query($sql);  
                        while ($tamp=mysql_fetch_array($dta)){
                        echo "
                        <tr>
                        <td>$tamp[0]</td>
                        <td>$tamp[1]</td>
                        <td>$tamp[2]</td>
                        <td>$tamp[3]</td>
                        <td><a href=editdata.php?id=$tamp[0]>edit </a><a href=datahapus.php?id=
$tamp[0]>hapus </a></td>
                        </tr>";} ?>
            </table>
</center>
<center>
            <table>
                        <tr>
                        <td><a href="inputdata.php">Tambah Data</a></td>
                        <td><a href="index.html">KEMBALI</a></td>
                        </tr>
            </table>
            <HR width=600 color="red">
</center>
</html>

  
editdata.php

<?php
include "koneksi.php";
            $id       = $_GET['id'];
            $sql = mysql_query ("SELECT * FROM tb_mhs WHERE nbi = '$id'");
            while ($hsl = mysql_fetch_array($sql)) {
            $nbi= $hsl[0];
            $nama= $hsl[1];
            $kelas= $hsl[2];
            $alamat= $hsl[3];}
?>
<html>
<head>
</head>
<body>
<center>
            <HR width=600 color="red">
            <h1>SILAHKAN EDIT DATA ANDA</h1>
            <HR width=600 color="red">
            <table><center>
<form name="input" action="<?php echo "dataedit.php?id=$id"; ?>" method="POST">
                                    <tr>
                                    <td>NBI</td>
                                    <td><input type="text" name="nbi" value="<?php echo "$nbi"; ?>" ></td>
                                    </tr>
                                    <tr>
                                    <td>Nama</td>
                        <td><input type="text" name="nama" value="<?php echo "$nama";?>">
</td>
                                    </tr>
                                    <tr>
                                    <td>Kelas</td>
                                    <td><input type="text" name="kelas" value="<?php echo "$kelas"; ?>">
</td>
                                    </tr>
                                    <tr>
                                    <td>Alamat</td>
                                    <td><input type="text" name="alamat" value="<?php echo "$alamat"; ?>">
</td>
                                    </tr>
                                    <tr>
                                    <td colspan=1 ></td>
                                    <td><input type="submit" value="simpan">
<input type="reset"  name="reset" value="reset">
                                    </tr>
                        </from>
            </table>
                        <HR width=600 color="red">
</center>
</body>
</html>

editdata.php

<?php
include "koneksi.php";
$id=$_GET['id'];
$nbi=$_POST["nbi"];
$nama=$_POST["nama"];
$kelas=$_POST["kelas"];
$alamat=$_POST["alamat"];
$edit="UPDATE tb_mhs SET nbi='$nbi', nama='$nama', kelas='$kelas', alamat='$alamat' WHERE nbi='$id' ";
mysql_query($edit);
header("location:lihatdata.php"); 
?>


hapusdata.php

<?php
include "koneksi.php";
$id= $_GET['id'];
$hapus = mysql_query("DELETE FROM tb_mhs where nbi = '$id'");
header("location:lihatdata.php"); 
?>


0 komentar:

Posting Komentar