Advertisement
cdsatrian

update data 20170123001

Jan 23rd, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.97 KB | None | 0 0
  1. //== view.php
  2. <html>
  3. <head>
  4.    <title>Tampil Data Mahasiswa Baru</title>
  5.       <script language="JavaScript">
  6.       function konfirmasi(kode) {
  7.         tanya = confirm('Anda yakin ingin menghapus data mahasiswa ini ?');
  8.         if (tanya == true) return true;
  9.         else return false;
  10.       }
  11.    </script>
  12. </head>
  13. <body>
  14. <body bgcolor="chartreuse">
  15. <H3><center>DATA MAHASISWA</center></H3>
  16. <table border='1' align='center' cellpadding='2' cellspacing='0'>
  17.     <tr bgcolor='Lightgreen'>
  18.         <th>KODE</th>
  19.         <th>NISN</th>
  20.         <th>Nama Mahasiswa</th>
  21.         <th>Tanggal Lahir</th>
  22.         <th>Tempat Lahir</th>
  23.         <th>Jenis Kelamin</th>
  24.         <th>Kewarganegaraan</th>
  25.         <th>Agama</th>
  26.         <th>Status</th>
  27.         <th>Alamat Rumah </th>
  28.         <th>Alamat Semarang</th>
  29.         <th>Telepon</th>
  30.         <th>Asal Sekolah</th>
  31.         <th>Jenis Ijazah</th>
  32.         <th>Status Ijazah</th>
  33.         <th>Jurusan Ijazah</th>
  34.         <th>Tahun Ijazah</th>
  35.         <th>Jurusan Pilihan</th>
  36.         <th>Status Mahasiswa</th>
  37.         <th>Pilihan Kuliah</th>
  38.         <th>Nama Ayah</th>
  39.         <th>Nama Ibu</th>
  40.         <th>Alamat</th>
  41.         <th>Pendidikan Ayah</th>
  42.         <th>Pendidikan Ibu</th>
  43.         <th>Pekerjaan Ayah</th>
  44.         <th>Pekerjaan Ibu</th>
  45.         <th colspan=2>AKSI</th>
  46.     </tr>
  47.     <?php
  48.     include "koneksi.php";
  49.     $koneksi=mysql_connect("localhost","root","");
  50.     $perintah_sql = "SELECT * FROM admin WHERE 1";
  51.     mysql_select_db("ta", $koneksi) or die("Gagal memilih database!");
  52.     $hasil_query = mysql_query($perintah_sql, $koneksi) or die ("Gagal memproses query!");
  53.     $jumlah_data = mysql_num_rows($hasil_query);
  54.     while ($row=mysql_fetch_row($hasil_query))
  55.     {
  56.         echo "<tr>";
  57.         for($i=0;$i<27;$i++)
  58.             echo "<td>{$row[$i]}</td>";
  59.         echo "<td><a href='edit.php?kode={$row[0]}'>Ubah</a></td>";
  60.         echo "<td><a href='delete.php?kode={$row[0]}' onclick=\"return konfirmasi('{$row[0]}')\">Hapus</a>";
  61.         echo "</tr>";
  62.     }
  63.     ?>
  64. </table>
  65. Jumlah data : <?php echo $jumlah_data;?> [<a href=add.php>Tambah Data</a>]
  66. </body>
  67. </html>
  68.  
  69.  
  70. //== edit.php
  71. <html>
  72. <head><title>Update Data Mahasiswa</title></head>
  73. <body bgcolor="purple">
  74. <?php
  75. include "koneksi.php";
  76. if(!isset($_GET['kode'])) header('location:view.php');$kode=$_GET['kode'];
  77. $query= "SELECT * FROM admin WHERE kode='$kode'";
  78. $hasil_query = mysql_query($query);
  79. $row= mysql_fetch_assoc($hasil_query);
  80. ?>
  81. <form method="post" action="update.php">
  82. <table align="center" border="1" cellpadding="5" cellspacing="0">
  83. <tr bgcolor="lightgreen">
  84. <td Colspan="3" align="center"><H3>Ubah Data Mahasiswa Baru</H3></td>
  85.     </tr>
  86.     <tr>
  87.         <td>Kode</td>
  88.         <td>:</td>
  89.         <td>
  90.         <input type="text" name="kode1"  size="40" value="<?php echo $row['kode']; ?>" >
  91.         <input type="hidden" name="kode" size="40" value=" <?php echo $row['kode']; ?>" >
  92.         </td>
  93.     </tr>
  94.    
  95.     <tr>
  96.         <td>NISN</td>
  97.         <td>:</td>
  98.         <td>
  99.         <input type="text" name="nisn" size="40" value="<?php echo $row['nisn']; ?>" >
  100.         </td>
  101.     </tr>
  102.    
  103.         <tr>
  104.         <td>Nama Mahasiswa</td>
  105.         <td>:</td>
  106.         <td>
  107.         <input type="text" name="nama" size="40"  value="<?php echo $row['nama']; ?>" >
  108.         </td>
  109.     </tr>
  110.    
  111.     <tr>
  112.         <td>Tanggal Lahir</td>
  113.         <td>:</td>
  114.         <td>
  115.         <input type="text" name="tgl_lahir" size="40" value="<?php echo $row['tgl_lahir']; ?>"  >
  116.         </td>
  117.     </tr>
  118.     <tr>
  119.         <td>Tempat Lahir</td>
  120.         <td>:</td>
  121.         <td>
  122.         <input type="text" name="tempat" size="40" value="<?php echo $row['tempat']; ?>" >
  123.         </td>
  124.     </tr>
  125.     <tr>
  126.         <td>Kelamin</td>
  127.         <td>:</td>
  128.         <td>
  129.         <select name="kelamin">
  130.         <option></option>
  131.         <option value="Pria" <?php if($row['kelamin']=='Pria'){ echo 'selected';} ?>>Pria</option>
  132.         <option value="Wanita" <?php if($row['kelamin']=='Wanita'){ echo 'selected';} ?>>Wanita</option>
  133.         </select>
  134.         </td>
  135.     </tr>
  136.     <tr>
  137.         <td>Kewarganegaraan</td>
  138.         <td>:</td>
  139.         <td>
  140.         <select name="warga">
  141.         <option></option>
  142.         <option value="WNI" <?php if($row['warga']=='WNI'){ echo 'selected';} ?>>WNI</option>
  143.         <option value="WNA" <?php if($row['warga']=='WNA'){ echo 'selected';} ?>>WNA</option>
  144.         </select>
  145.         </td>
  146.     </tr>
  147.     <tr>
  148.         <td>Agama</td>
  149.         <td>:</td>
  150.         <td>
  151.         <select name="agama">
  152.         <option></option>
  153.         <?php
  154.         $agama=array('islam','katolik','kristen','budha','hindu','lain');
  155.         foreach($agama as $a) echo "<option value='{$a}'".($row['agama']==$a?' selected':'').">".ucfirst($a)."</option>";
  156.         ?>
  157.         </select>
  158.         </td>
  159.     </tr>
  160.     <tr>
  161.         <td>Status</td>
  162.         <td>:</td>
  163.         <td>
  164.         <select name="status">
  165.         <option></option>
  166.         <option value="belum" <?php if($row['status']=='belum'){ echo 'selected';} ?>>Belum Nikah</option>
  167.         <option value="nikah" <?php if($row['status']=='nikah'){ echo 'selected';} ?>>Nikah</option>
  168.         </td>
  169.     </tr>
  170.     <tr>
  171.         <td>Alamat Rumah</td>
  172.         <td>:</td>
  173.         <td>
  174.         <input type="text" name="rumah" size="40" value="<?php echo $row['rumah']; ?>">
  175.         </td>
  176.     </tr>
  177.     <tr>
  178.         <td>Alamat Semarang</td>
  179.         <td>:</td>
  180.         <td>
  181.         <input type="text" name="smg" size="40"value="<?php echo $row['smg']; ?>">
  182.         </td>
  183.     </tr>
  184.     <tr>
  185.         <td>Telepon</td>
  186.         <td>:</td>
  187.         <td>
  188.         <input type="text" name="telp" size="40" value="<?php echo $row['telp']; ?>">
  189.         </td>
  190.     </tr>
  191.     <tr>
  192.         <td>Asal Sekolah</td>
  193.         <td>:</td>
  194.         <td>
  195.         <input type="text" name="asal" size="40" value="<?php echo $row['asal']; ?>">
  196.         </td>
  197.     </tr>
  198.     <tr>
  199.         <td>Jenis Ijazah</td>
  200.         <td>:</td>
  201.         <td>
  202.         <select name="jenis">
  203.         <option></option>
  204.         <?php
  205.         $jenis=array('SMA','SMK','Ponpes','MA','lain');
  206.         foreach($jenis as $j) echo "<option value='{$j}'".($row['jenis']==$j?' selected':'').">{$j}</option>";
  207.         ?>
  208.         </select>
  209.         </td>
  210.     </tr>
  211.     <tr>
  212.         <td>Status Ijazah</td>
  213.         <td>:</td>
  214.         <td>
  215.         <select name="statuss">
  216.         <option></option>
  217.         <?php
  218.         $statuss=array('negeri','swasta','luar negeri','lain');
  219.         foreach($statuss as $s) echo "<option value='{$s}'".($row['statuss']==$s?' selected':'').">".ucwords($s)."</option>";
  220.         ?>
  221.         </select>
  222.         </td>
  223.     </tr>
  224.     <tr>
  225.         <td>Jurusan Ijazah</td>
  226.         <td>:</td>
  227.         <td>
  228.         <select name="jurusan">
  229.         <option></option>
  230.         <?php
  231.         $jurusan=array('IPA','IPS','Bahasa','Agama','Lain');
  232.         foreach($jurusan as $j) echo "<option value='{$j}'".($row['jurusan']==$j?' selected':'').">{$j}</option>";
  233.         ?>
  234.         </select>
  235.         </td>
  236.     </tr>
  237.     <tr>
  238.         <td>Tahun Ijazah</td>
  239.         <td>:</td>
  240.         <td>
  241.         <input type="text" name="thun" size="40" value="<?php echo $row['thun']; ?>">
  242.         </td>
  243.     </tr>
  244.     <tr>
  245.         <td>Jurusan Pilihan</td>
  246.         <td>:</td>
  247.         <td>
  248.         <select name="jurusan_pilihan">
  249.         <option></option>
  250.         <option value="teknik mesin" <?php if($row['jurusan_pilihan']=='teknik mesin'){ echo 'selected';} ?>>Teknik Mesin</option>
  251.         <option value="Teknik kimia" <?php if($row['jurusan_pilihan']=='Teknik kimia'){ echo 'selected';} ?>>Teknik Kimia</option>
  252.         <option value="Teknik Informatika" <?php if($row['jurusan_pilihan']=='Teknik Informatika'){ echo 'selected';} ?>>Teknik Informatika</option>
  253.         <option value="Farmasi" <?php if($row['jurusan_pilihan']=='Farmasi'){ echo 'selected';} ?>>Farmasi</option>
  254.         <option value="Manajemen" <?php if($row['jurusan_pilihan']=='Manajemen'){ echo 'selected';} ?>>Manajemen</option>
  255.         <option value="Akuntansi" <?php if($row['jurusan_pilihan']=='Akuntansi'){ echo 'selected';} ?>>Akuntansi</option>
  256.         <option value="Hukum" <?php if($row['jurusan_pilihan']=='Hukum'){ echo 'selected';} ?>>Hukum</option>
  257.         <option value="Agribisnis" <?php if($row['jurusan_pilihan']=='Agribisnis'){ echo 'selected';} ?>>Agribisnis</option>
  258.         <option value="PAI" <?php if($row['jurusan_pilihan']=='PAI'){ echo 'selected';} ?>>PAI</option>
  259.         <option value="PGMI" <?php if($row['jurusan_pilihan']=='PGMI'){ echo 'selected';} ?>>PGMI</option>
  260.         <option value="Hukum Ekonomi Syariah" <?php if($row['jurusan_pilihan']=='Hukum Ekonomi syariah'){ echo 'selected';} ?>>Hukum Ekonomi Syari'ah</option>
  261.         <option value="Ilmu Politik" <?php if($row['jurusan_pilihan']=='Ilmu Politik'){ echo 'selected';} ?>>Ilmu Politik</option>
  262.         <option value="Hub.internasional" <?php if($row['jurusan_pilihan']=='Hub.internasional'){ echo 'selected';} ?>>Hub. Internasional</option>
  263.         <option value="Ekonomi Syariah" <?php if($row['jurusan_pilihan']=='Ekonomi Syariah'){ echo 'selected';} ?>>Ekonomi Syari'ah</option>
  264.         <option value="Pend. Olahraga" <?php if($row['jurusan_pilihan']=='Pend. Olahraga'){ echo 'selected';} ?>>Pend. Olahraga</option>
  265.         <option value="Kedokteran" <?php if($row['jurusan_pilihan']=='Kedokteran'){ echo 'selected';} ?>>Kedokteran</option></select>
  266.         </td>
  267.     </tr>
  268.     <tr>
  269.         <td>Status Mahasiswa</td>
  270.         <td>:</td>
  271.         <td>
  272.         <select name="sts_mhs">
  273.         <option></option>
  274.         <option value="baru" <?php if($row['sts_mhs']=='baru'){ echo 'selected';} ?>>Baru</option>
  275.         <option value="transfer" <?php if($row['sts_mhs']=='transfer'){ echo 'selected';} ?>>Transfer</option>
  276.         </select>
  277.         </td>
  278.     </tr>
  279.     <tr>
  280.         <td>Pilihan Kuliah</td>
  281.         <td>:</td>
  282.         <td>
  283.         <select name="pilih_kuliah">
  284.         <option></option>
  285.         <option value="reguler" <?php if($row['pilih_kuliah']=='reguler'){ echo 'selected';} ?>>Reguler</option>
  286.         <option value="Ekstensi" <?php if($row['pilih_kuliah']=='Ekstensi'){ echo 'selected';} ?>>Ekstensi</option></select>
  287.         </td>
  288.     </tr>
  289.     <tr class="genap">
  290.         <td>Nama Ayah</td>
  291.         <td>:</td>
  292.         <td>
  293.         <input type="text" name="ayah" size="40"value="<?php echo $row['ayah']; ?>">
  294.         </td>
  295.     </tr>  
  296.     <tr>
  297.         <td>Nama Ibu</td>
  298.         <td>:</td>
  299.         <td>
  300.         <input type="text" name="ibu" size="40"value="<?php echo $row['ibu']; ?>">
  301.         </td>
  302.     </tr>
  303.     <tr>
  304.         <td>Alamat</td>
  305.         <td>:</td>
  306.         <td>
  307.         <input type="text" name="almt_ort" size="40"value="<?php echo $row['almt_ort']; ?>">
  308.         </td>
  309.     </tr>
  310.     <tr>
  311.         <td>Pendidikan Ayah</td>
  312.         <td>:</td>
  313.         <td>
  314.         <select name="pdk_orta">
  315.         <option></option>
  316.         <option value="SD" <?php if($row['pdk_orta']=='SD'){ echo 'selected';} ?>>SD</option>
  317.         <option value="SLTP" <?php if($row['pdk_orta']=='SLTP'){ echo 'selected';} ?>>SLTP</option>
  318.         <option value="SLTA" <?php if($row['pdk_orta']=='SLTA'){ echo 'selected';} ?>>SLTA</option>
  319.         <option value="Sarjana" <?php if($row['pdk_orta']=='Sarjana'){ echo 'selected';} ?>>Sarjana</option>
  320.         <option value="Sarjana Muda" <?php if($row['pdk_orta']=='Sarjana Muda'){ echo 'selected';} ?>>Sarjana Muda</option>
  321.         <option value="Magister" <?php if($row['pdk_orta']=='Magister'){ echo 'selected';} ?>>Magister</option>
  322.         <option value="Profesor" <?php if($row['pdk_orta']=='Profesor'){ echo 'selected';} ?>>Profesor</option>
  323.         <option value="Doktor" <?php if($row['pdk_orta']=='Doktor'){ echo 'selected';} ?>>Doktor</option>
  324.         <option value="Lain" <?php if($row['pdk_orta']=='Lain'){ echo 'selected';} ?>>Lain</option>
  325.         </select>
  326.         </td>
  327.     </tr>
  328.     <tr>
  329.         <td>Pendidikan Ibu</td>
  330.         <td>:</td>
  331.         <td>
  332.         <select name="pdk_orti">
  333.         <option></option>
  334.         <option value="SD" <?php if($row['pdk_orti']=='SD'){ echo 'selected';} ?>>SD</option>
  335.         <option value="SLTP" <?php if($row['pdk_orta']=='SLTP'){ echo 'selected';} ?>>SLTP</option>
  336.         <option value="SLTA" <?php if($row['pdk_orta']=='SLTA'){ echo 'selected';} ?>>SLTA</option>
  337.         <option value="Sarjana" <?php if($row['pdk_orta']=='Sarjana'){ echo 'selected';} ?>>Sarjana</option>
  338.         <option value="Sarjana Muda" <?php if($row['pdk_orta']=='Sarjana Muda'){ echo 'selected';} ?>>Sarjana Muda</option>
  339.         <option value="Magister" <?php if($row['pdk_orta']=='Magister'){ echo 'selected';} ?>>Magister</option>
  340.         <option value="Profesor" <?php if($row['pdk_orta']=='Profesor'){ echo 'selected';} ?>>Profesor</option>
  341.         <option value="Doktor" <?php if($row['pdk_orta']=='Doktor'){ echo 'selected';} ?>>Doktor</option>
  342.         <option value="Lain" <?php if($row['pdk_orta']=='Lain'){ echo 'selected';} ?>>Lain</option>
  343.         </select>
  344.         </td>
  345.     </tr>
  346.     <tr>
  347.         <td>Pekerjaan Ayah</td>
  348.         <td>:</td>
  349.         <td>
  350.         <select name="pkrayah">
  351.         <option></option>
  352.         <option value="PNS" <?php if($row['pkrayah']=='PNS'){ echo 'selected';} ?>>PNS</option>
  353.         <option value="TNI" <?php if($row['pkrayah']=='TNI'){ echo 'selected';} ?>>TNI</option>
  354.         <option value="POLRI" <?php if($row['pkrayah']=='POLRI'){ echo 'selected';} ?>>POLRI</option>
  355.         <option value="WIRASWASTA" <?php if($row['pkrayah']=='WIRASWASTA'){ echo 'selected';} ?>>WIRASWASTA</option>
  356.         <option value="PETANI" <?php if($row['pkrayah']=='PETANI'){ echo 'selected';} ?>>PETANI</option>
  357.         <option value="PENSIUNAN" <?php if($row['pkrayah']=='PENSIUNAN'){ echo 'selected';} ?>>PENSIUNAN</option>
  358.         <option value="PEGAWAI SWASTA" <?php if($row['pkrayah']=='PEGAWAI SWASTA'){ echo 'selected';} ?>>PEGAWAI SWASTA</option>
  359.         <option value="LAIN" <?php if($row['pkrayah']=='LAIN'){ echo 'selected';} ?>>LAIN</option>
  360.         </select>
  361.         </td>
  362.     </tr>
  363.     <tr>
  364.         <td>Pekerjaan Ibu</td>
  365.         <td>:</td>
  366.         <td>
  367.         <select name="pkribu">
  368.         <option></option>
  369.         <option value="PNS" <?php if($row['pkribu']=='PNS'){ echo 'selected';} ?>>PNS</option>
  370.         <option value="TNI" <?php if($row['pkrayah']=='TNI'){ echo 'selected';} ?>>TNI</option>
  371.         <option value="POLRI" <?php if($row['pkrayah']=='POLRI'){ echo 'selected';} ?>>POLRI</option>
  372.         <option value="WIRASWASTA" <?php if($row['pkrayah']=='WIRASWASTA'){ echo 'selected';} ?>>WIRASWASTA</option>
  373.         <option value="PETANI" <?php if($row['pkrayah']=='PETANI'){ echo 'selected';} ?>>PETANI</option>
  374.         <option value="PENSIUNAN" <?php if($row['pkrayah']=='PENSIUNAN'){ echo 'selected';} ?>>PENSIUNAN</option>
  375.         <option value="PEGAWAI SWASTA" <?php if($row['pkrayah']=='PEGAWAI SWASTA'){ echo 'selected';} ?>>PEGAWAI SWASTA</option>
  376.         <option value="LAIN" <?php if($row['pkrayah']=='LAIN'){ echo 'selected';} ?>>LAIN</option>
  377.         </select>
  378.         </td>
  379.     </tr>
  380.    
  381. <tr align=center>
  382. <td Colspan=3>
  383. <table align="center" width="400" height="100"  cellpadding="4" cellspacing="0">
  384. <tr bgcolor="deepskyblue"><td>
  385. <input type="submit" value="Update" name="simpan"> [<a href=view.php>Lihat Data Mahasiswa Baru</a>]
  386. </td></tr>
  387. </table>
  388. </form>
  389. </body>
  390. </html>
  391.  
  392.  
  393. //== update.php
  394. <html>
  395. <head>
  396. <title>Update Data Mahasiswa Baru</title>
  397. </head>
  398. <body background="coral">
  399. <?php
  400. include "koneksi.php";
  401. if (isset($_POST['simpan'])){
  402.     $koneksi = mysql_connect ("localhost","root","");
  403.     mysql_select_db("ta",$koneksi);
  404.     $query = "
  405.         UPDATE
  406.             admin
  407.         SET
  408.             kode='{$_POST['kode1']}',
  409.             nisn='{$_POST['nisn']}',
  410.             nama='{$_POST['nama']}',
  411.             tgl_lahir='{$_POST['tgl_lahir']}',
  412.             tempat='{$_POST['tempat']}',
  413.             kelamin='{$_POST['kelamin']}',
  414.             warga='{$_POST['warga']}',
  415.             agama='{$_POST['agama']}',
  416.             status='{$_POST['status']}',
  417.             rumah='{$_POST['rumah']}',
  418.             smg='{$_POST['smg']}',
  419.             telp='{$_POST['telp']}',
  420.             asal='{$_POST['asal']}',
  421.             jenis='{$_POST['jenis']}',
  422.             statuss='{$_POST['statuss']}',
  423.             jurusan='{$_POST['jurusan']}',
  424.             thun='{$_POST['thun']}',
  425.             jurusan_pilihan='{$_POST['jurusan_pilihan']}',
  426.             sts_mhs='{$_POST['sts_mhs']}',
  427.             pilih_kuliah='{$_POST['pilih_kuliah']}',
  428.             ayah='{$_POST['ayah']}',
  429.             ibu='{$_POST['ibu']}',
  430.             almt_ort='{$_POST['almt_ort']}',
  431.             pdk_orta='{$_POST['pdk_orta']}',
  432.             pdk_orti='{$_POST['pdk_orti']}',
  433.             pkrayah='{$_POST['pkrayah']}',
  434.             pkribu='{$_POST['pkribu']}'
  435.         WHERE
  436.             kode='{$_POST['kode']}'
  437.         ";
  438.     $hasil=mysql_query($query);
  439.     if($hasil){
  440.         echo "Data Telah Diupdate";
  441.         echo "<br>";
  442.     }
  443. }
  444. ?>
  445. [<a href=view.php>Lihat Data Mahasiswa Baru</a>]
  446. </body>
  447. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement