Rabu, 22 Januari 2014

Screenshot Tugas
File koneksi.php
<?php
$sambung = mysql_connect('localhost','root','') or die ('gagal koneksi');
$pilih_db= mysql_select_db('data_mhs') or die('Data Tidak Terpilih');
?>

File index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tugas Web Dasar</title>
</head>

<body>
<?php include('koneksi.php'); ?>
<table width="800" border="1" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td colspan="4" align="center"><strong>LIHAT DATA MAHASISWA</strong> <a href="tambah.php">Tambah Data</a></td>
  </tr>
  <tr> 
    <td bgcolor="#0099CC">NIM</td>
    <td bgcolor="#0099CC">NAMA</td>
    <td bgcolor="#0099CC">JURUSAN</td>
    <td bgcolor="#0099CC">OPSI</td>
  </tr>
  <?php
   $code = "select * from kelas_e order by id DESC";
 $q = mysql_query($code);
 while($data=mysql_fetch_array($q)){
  ?>
  <tr>
    <td><?php echo $data['nim']; ?></td>
    <td><?php echo $data['nama']; ?></td>
    <td><?php echo $data['jurusan']; ?></td>
    <td>
     <a href="edit.php?id=<?php echo $data['id'];?>">Edit</a>
     <a onclick="return confirm('Hapus Data Ini?')" href="hapus.php?id=<?php echo $data['id'];?>">Hapus</a>
    </td>
  </tr>
 <?php } ?>
  <tr>
    <td colspan="4"><p>Oleh: Achmad Munawir Noviandri | Kelas E | L200130184</p>
    </td>
  </tr>
</table>
</body>
</html>

File tambah.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tambah Data</title>
</head>

<body>
<?php include('koneksi.php'); ?>
<form method="post">
<table width="800" border="1" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td colspan="2" align="center"><strong>TAMBAH DATA MAHASISWA</strong> <a href="index.php">kembali</a></td>
  </tr>
  <tr>
    <td>NIM</td>
    <td><input type="text" name="nim" required /></td>
  </tr>
  <tr>
    <td>NAMA</td>
    <td><input type="text" name="nama" required /></td>
  </tr>
  <tr>
    <td>JURUSAN</td>
    <td><input type="text" name="jurusan" required /></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" name="tambah" value="Tambah Data" /> <input type="reset"  /></td>
  </tr>
</table>
</form>
<?php
 $nama = $_POST['nama'];
 $nim = $_POST['nim'];
 $jurusan = $_POST['jurusan'];
 $tambah = $_POST['tambah'];
 
 if($tambah){
  $code1 = "insert into kelas_e(nama,nim,jurusan) values('$nama','$nim','$jurusan')";
  $add = mysql_query($code1);
  echo("<script>alert('Data Berhasil di Tambah')</script>
   <meta http-equiv='refresh' content='0;url=index.php' />
  ");
  
 } // tutupnya if($tamnbah)
?>
</body>
</html>

File hapus.php
<?php 
 include('koneksi.php');
 $id = $_GET['id'];
 $code_hapus = "delete from kelas_e where id='$id'";
 $hapus = mysql_query($code_hapus);
  echo("<script>alert('Data Berhasil di Hapus')</script>
   <meta http-equiv='refresh' content='0;url=index.php' />
  ");
 
?>

File edit.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Data</title>
</head>

<body>
<?php include('koneksi.php');
 $id = $_GET['id'];
 $code_edit = "select * from kelas_e where id='$id'";
 $ed = mysql_query($code_edit);
 while($t=mysql_fetch_array($ed)){
 ?>
<form method="post">
<table width="800" border="1" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td colspan="2" align="center"><strong>TAMBAH DATA MAHASISWA</strong> <a href="index.php">kembali</a></td>
  </tr>
  <tr>
    <td>NIM</td>
    <td><input value="<?php echo $t['nim']; ?>"  type="text" name="nim" required /></td>
  </tr>
  <tr>
    <td>NAMA</td>
    <td><input value="<?php echo $t['nama']; ?>" type="text" name="nama" required /></td>
  </tr>
  <tr>
    <td>JURUSAN</td>
    <td><input value="<?php echo $t['jurusan']; ?>" type="text" name="jurusan" required /></td>
  </tr>
  <tr>
    <td colspan="2"><input type="submit" name="tambah" value="Edit Data" /> <input type="reset"  /></td>
  </tr>
</table>
</form>
<?php
} // tutup while
 $nama = $_POST['nama'];
 $nim = $_POST['nim'];
 $jurusan = $_POST['jurusan'];
 $tambah = $_POST['tambah'];
 
 if($tambah){
  $code1 = "update kelas_e set nim='$nim', nama='$nama', jurusan='$jurusan' where id='$id'";
  $edit = mysql_query($code1);
  echo("<script>alert('Edit Data Berhasil')</script>
   <meta http-equiv='refresh' content='0;url=index.php' />
  ");
  
 } // tutupnya if($tamnbah)
?>
</body>
</html>

0 komentar:

Posting Komentar