justhrun

view.php

Jun 17th, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5.         <title>List Nilai per Matakuliah</title>
  6.         <style type="text/css">
  7.         table.hovertable {
  8.                 font-family: verdana,arial,sans-serif;
  9.                 font-size:12px;
  10.                 color:#333333;
  11.                 border-width: 1px;
  12.                 border-color: #999999;
  13.                 border-collapse: collapse;
  14.         }
  15.         table.hovertable th {
  16.                 background-color:#c3dde0;
  17.                 border-width: 1px;
  18.                 padding: 8px;
  19.                 border-style: solid;
  20.                 border-color: #a9c6c9;
  21.         }
  22.         table.hovertable tr {
  23.                 background-color:#d4e3e5;
  24.         }
  25.         table.hovertable td {
  26.                 border-width: 1px;
  27.                 padding: 8px;
  28.                 border-style: solid;
  29.                 border-color: #a9c6c9;
  30.         }
  31.         input {
  32.             alignment-adjust: central;
  33.         }
  34.         </style>
  35.  
  36.     </head>
  37.     <body>
  38.         <?php
  39.         $koneksi = mysql_connect('localhost', 'root', '') or die (mysql_error());
  40.         mysql_select_db('kuliah', $koneksi) or die (mysql_error());
  41.        
  42.         ?>
  43.        
  44.         <table class="hovertable">
  45.             <th>No.</th>
  46.             <th>Nim</th>
  47.             <th>Nama</th>
  48.             <th>Kode MK</th>
  49.             <th>Nama MK</th>
  50.             <th>Nilai</th>
  51.             <form action="view.php" method="POST">  
  52.                        
  53.         <?php
  54.         $query_all = "SELECT * FROM angka";
  55.         $result_all = mysql_query($query_all) or die (mysql_error());
  56.         $count = mysql_num_rows($result_all);
  57.         $nomor = 1;
  58.         while ($rows = mysql_fetch_object($result_all)){
  59.         ?>
  60.             <tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
  61.                                                 <td><?php echo $nomor++; ?></td>
  62.                     <td><input type="text" id="nim" name="nim[]" value="<?php echo $rows->nim; ?>"></td>
  63.                                         <td><input type="text" id="nama" name="nama[]" value="<?php echo $rows->nama; ?>"></td>
  64.                     <td><input type="text" id="kodemk" name="kodemk[]" value="<?php echo $rows->kodemk; ?>"></td>
  65.                                         <td><input type="text" id="namamk" name="namamk[]" value="<?php echo $rows->namamk; ?>"></td>
  66.                     <td><input type="text" size="2" name="nilai[]" id="nilai" value="<?php echo $rows->nilai; ?>"</td>
  67.                              
  68.             </tr>
  69.         <?php
  70.         }
  71.         ?>
  72.             <tr>
  73.                 <td>
  74.                     <input type="submit" name="submit" value="Simpan">
  75.                     </form>
  76.                 </td>
  77.             </tr>
  78.            
  79.         </table>
  80.        
  81.         <?php
  82.         // Multipe insert case
  83.         if(isset($_POST['submit'])) {
  84.             $nim = $_POST['nim'];
  85.             $nama = $_POST['nama'];
  86.             $kodemk = $_POST['kodemk'];
  87.             $namamk = $_POST['namamk'];
  88.             $nilai = $_POST['nilai'];          
  89.             if($nim > 0) {
  90.                 $qry = "INSERT INTO angka(nim, nama, kodemk, namamk, nilai, Dates) VALUES "; // Split the mysql_query
  91.                 for($i=0; $i<count($nim); $i++) {
  92.                     $qry .= "('".$nim[$i]."','".$nama[$i]."','".$kodemk[$i]."','".$namamk[$i]."', '".$nilai[$i]."', NOW()), ";
  93.                 }
  94.                 $qry    = substr($qry, 0, strlen($qry)-2);
  95.                 $insert = mysql_query($qry); // Execute the mysql_query
  96.             }
  97.             // Redirect for each cases
  98.             if($insert) {
  99.                 $msg = '<script type="text/javascript">window.location.href = "?view&result=added";</script>';
  100.             }
  101.             else {
  102.                 $msg = '<script type="text/javascript">alert("Server Error, Kindly Try Again");</script>';
  103.             }
  104.  
  105.             echo "Data telah diupdate <a href=view.php>Refresh</a>";
  106.             mysql_close($koneksi);
  107.             }      
  108.                
  109.         ?>
  110.     </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment