Advertisement
cdsatrian

kdbrg

Jun 27th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.57 KB | None | 0 0
  1. //--begin of combo.php file
  2. <html>
  3. <head>
  4. <title></title>
  5. <script src="../datetimepicker_css.js"></script>
  6. </head>
  7. <body>
  8. <hr />
  9. <h3>.: Input Data Barang :.</h3>
  10. <form method="post" action="combo.php">
  11.   Jumlah Item Barang :
  12.     <input type="text" name="jum">
  13.     <input type="submit" name="submit" value="Submit">
  14. </form>
  15. <?
  16. if($_POST){
  17.   //include '../../koneksi.php';
  18.   $C= mysql_connect("localhost", "root", "root") or die(mysql_error());
  19.   mysql_select_db("pln");
  20.  
  21.   function select_barang(){
  22.     $select= "<select name='KD_BRG[]' >";
  23.     $query = mysql_query("SELECT a.KD_BRG, a.NM_BRG, b.SATUAN FROM t_brg a, t_satuan b WHERE a.ID_SAT=b.ID_SAT")or die(mysql_error());  
  24.     while ($row = mysql_fetch_array($query)) {  
  25.       $select.= '<option value="' . $row['KD_BRG'] . '">' . $row['NM_BRG'] . '('.$row['SATUAN'].')</option>';  
  26.     }  
  27.     $select.="</select> *Pilih dari list disamping";
  28.     return $select;
  29.   }
  30.   $jum = $_POST['jum'];
  31.   $tug=mysql_query("SELECT MAX(CAST(substring(ID_MSK, 4)AS UNSIGNED)) FROM t_msk ");
  32.   $arrData2 = mysql_fetch_row($tug);
  33.   $gabtug = 'TUG'.($arrData2[0] ? ++$arrData2[0] : 1);
  34.   $datanim = $_POST['KD_BRG'];
  35.   $qry = "SELECT a.C_TIM, a.NM_KETUA, a.NM_KASIR, a.NM_ENTRY, a.NM_APP,
  36.  b.NM_BIRO, c.LOKASI FROM t_tim a, t_biro b, t_lokasi c
  37.  WHERE a.C_BIRO=b.C_BIRO AND c.C_LOKASI=b.C_LOKASI
  38.  ORDER BY a.C_TIM ASC";
  39.   $hsl = mysql_query($qry);
  40.   $ary = mysql_fetch_array($hsl);
  41. ?>
  42. <form method="post" action="insert.php">
  43. <h3>.: Data Tim Sarling :. </h3>
  44. <table width="339" border="0">
  45.   <tr>
  46.     <td width="138">Nama Tim</td>
  47.     <td width="10">:</td>
  48.     <td width="162"><input type="text" name="C_TIM" id="C_TIM" value="<? echo $ary['C_TIM']; ?>" /></td>
  49.     <td width="11">&nbsp;</td>
  50.   </tr>
  51.   <tr>
  52.     <td>Nama APP</td>
  53.     <td>:</td>
  54.     <td><input type="text" name="NM_APP" id="NM_APP" value="<? echo $ary['NM_APP']; ?>"/></td>
  55.     <td>&nbsp;</td>
  56.   </tr>
  57.   <tr>
  58.     <td>Nama Biro</td>
  59.     <td>&nbsp;</td>
  60.     <td><input type="text" name="NM_BIRO" id="NM_BIRO" value="<? echo $ary['NM_BIRO']; ?>"/></td>
  61.     <td>&nbsp;</td>
  62.   </tr>
  63.   <tr>
  64.     <td>Lokasi</td>
  65.     <td>:</td>
  66.     <td><input type="text" name="LOKASI" id="LOKASI" value="<? echo $ary['LOKASI']; ?>"/></td>
  67.     <td>&nbsp;</td>
  68.   </tr>
  69. </table>
  70.   <hr />
  71.   <h2>.: INPUT DATA BARANG SEBANYAK <?=$jum;?> :.</h2>
  72.   <table border=0 >
  73.     <tr>
  74.     <td>No Masuk </td>
  75.   <td><input type="text" name="ID_MSK" id="ID_MSK" value="<? echo $gabtug; ?>"></td>
  76.   </tr>
  77.   <tr>
  78.   <td>Tanggal </td>
  79.   <td>    
  80.     <input type="text" name="TGL_MSK" id="TGL_MSK" />
  81.       <img src="../images2/cal.gif" alt="" height="18" style="cursor:pointer" onClick="javascript:NewCssCal('TGL_MSK','yyyyMMdd')"/></td>
  82.   </tr>
  83.   <tr>
  84.   <td>Nomor KWH</td>
  85.   <td>  
  86.     <input type="text" name="NO_KWH" id="NO_KWH"></td>
  87.   </tr>
  88.   <tr>
  89.   <td>Merek </td>
  90.   <td>    
  91.     <input type="text" name="MERK" id="MERK"></td>
  92.   </tr>
  93. <?php
  94.   for ($i=1; $i<=$n; $i++){
  95.    echo "
  96.   <tr>
  97.     <tr>
  98.     <td>Nama Barang</td>
  99.    <td>".select_barang()."</td>
  100.    </tr>
  101.     <tr>
  102.     <td>Jumlah</td>
  103.    <td><input type='text' name='JML_MSK[]'></td>
  104.     </tr>
  105.   </tr>";
  106.   }
  107. ?>
  108. </table>
  109.   </p>
  110.     <input type="hidden" name="jum"  value="<? echo $jum;?>" />
  111.    <input type="hidden" name="C_TIM" value="<? echo $ary['C_TIM']; ?>" />
  112.    <input type="submit" name="submit" value="Submit">
  113.   <br></form>
  114. <?php
  115. }
  116. ?>
  117. <p>
  118. </p>
  119. </body>
  120. </html>
  121. //--end of combo.php file
  122. ======
  123. // -- begin of insert.php file
  124. <?php
  125. mysql_connect("localhost", "root", "root");
  126. mysql_select_db("pln");
  127. $jumlah_data  = $_POST['jum']; // membaca jumlah data
  128. $tim       = $_POST['C_TIM'];
  129. $no       = $_POST['ID_MSK'];
  130. $kwh       = $_POST['NO_KWH'];
  131. $tgl       = $_POST['TGL_MSK'];
  132. $merk       = $_POST['MERK'];
  133. for ($i=0; $i<$jumlah_data; $i++){
  134.   $kd_brg = $_POST['KD_BRG'];
  135.   $jml_msk = $_POST['JML_MSK'];
  136.   if ((!empty($kd_brg[$i])) && (!empty($jml_msk[$i]))){
  137.     $query   = "INSERT INTO t_msk(ID_MSK, KD_BRG, TGL_MSK) VALUES ('$no', '".$kd_brg[$i]."', '$tgl')";
  138.     $qry   = "INSERT INTO td_msk(NO_MSK, NO_KWH, C_TIM, ID_MSK, JML_MSK) VALUES ('', '$kwh', '$tim', '$no','".$jml_msk[$i]."')";
  139.     $kwh   = "INSERT INTO t_meter VALUES ('$kwh', '0', '0', '$merk')";
  140.     $hasil   = mysql_query($query)  or die(mysql_error());
  141.     $has   = mysql_query($qry) or die(mysql_error());
  142.     $hasq   = mysql_query($kwh)  or die(mysql_error());
  143.     if ($hasil&&$has&&$hasq) {
  144.       echo "Input data sukses<br>";
  145.     } else {
  146.       echo "Input data gagal<br>";
  147.     }
  148.   }
  149. }
  150. ?>
  151. //--end of insert.php file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement