kura2yamato

perbaikan 003

Aug 14th, 2021
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.00 KB | None | 0 0
  1. //proses query
  2. <?php
  3. //mysql_select_db($name_database, $database);
  4. $database =   @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');//sesuaikan
  5.  
  6. if (!$database) {
  7.     /* Use your preferred error logging method here */
  8.     error_log('Connection error: ' . mysqli_connect_error());
  9. }
  10.  
  11. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form14")) {
  12.   $data = $nTps = $_POST['jumlah_tps'];
  13.   //for($i=1;$i<=$data;$i++)
  14.   {
  15.  
  16.         $id = autonumber("tps", "id", 1, "");      
  17.         $code_region = 1;
  18.         $name_region = $_POST['name_region'];
  19.  
  20.         $code_prov = $_POST['code_prov'];
  21.         $row1 = mysql_fetch_assoc(mysqli_query("select * from master_region where code_region='$code_prov'",$database));
  22.         $name_prov = $row1['name_region'];
  23.  
  24.         $code_kab = $_POST['code_kab'];
  25.         $row2 = mysql_fetch_assoc(mysqli_query("select * from master_region where code_region='$code_kab'",$database));
  26.         $name_kab = $row2['name_region'];
  27.        
  28.         $code_kec = $_POST['code_kec'];
  29.         $row3 = mysql_fetch_assoc(mysqli_query("select * from master_region where code_region='$code_kec'",$database));
  30.         $name_kec = $row3['name_region'];
  31.  
  32.         $code_kel = $_POST['code_kel'];
  33.         $row4 = mysql_fetch_assoc(mysqli_query("select * from master_region where code_region='$code_kel'",$database));
  34.         $name_kel = $row4['name_region'];
  35.  
  36.         //$code_tps = autostring("tps","code_tps",$code_kel,4,$code_kel.".");
  37.         $code_tps =  "tps"."code_tps".$code_kel.4,$code_kel;
  38.         $name_tps = substr($code_tps,-4);
  39.         $password = $code_tps;
  40.         $role = "CHECKER";
  41.  
  42.       $query=mysqli_fetch_assoc(mysqli_query("SELECT * FROM tps WHERE code_tp like  '$code_tps%'",$database));
  43.       if ($query ){
  44.         echo "<script>alert('Kode TPS ".$code_tps." sudah terdaftar !!!'); window.location = 'master-data'</script>";
  45.       } else {
  46.           for($iTps=0;$iTps<$nTps;$iTps++)
  47.           {
  48.               $code_tps = autostring("tps","code_tps",$code_kel,4,$code_kel.".");
  49.               $code_tps .= sprintf("%04s",$iTps);
  50.               $name_tps = substr($code_tps,-4);
  51.               $password = $code_tps;
  52.               $insertSQL = sprintf("INSERT HIGH_PRIORITY INTO tps (id, code_region, name_region, code_prov, name_prov, code_kab, name_kab, code_kec, name_kec, code_kel, name_kel, code_tps, name_tps, password, role) VALUES (%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s)",
  53.                   GetSQLValueString($id, "text"),
  54.                   GetSQLValueString($code_region, "text"),
  55.                   GetSQLValueString($name_region, "text"),
  56.                   GetSQLValueString($code_prov, "text"),
  57.                   GetSQLValueString($name_prov, "text"),
  58.                   GetSQLValueString($code_kab, "text"),
  59.                   GetSQLValueString($name_kab, "text"),
  60.                   GetSQLValueString($code_kec, "text"),
  61.                   GetSQLValueString($name_kec, "text"),
  62.                   GetSQLValueString($code_kel, "text"),
  63.                   GetSQLValueString($name_kel, "text"),
  64.                   GetSQLValueString($code_tps2, "text"),
  65.                   GetSQLValueString($name_tps, "text"),
  66.                   GetSQLValueString($password, "text"),
  67.                   GetSQLValueString($role, "text"));
  68.             $Result1 = mysqli_query($insertSQL, $database) or die(mysql_error());              
  69.           }
  70.         echo '<script>alert("Data berhasil dibuat"); location.href="master-data"</script>';
  71.       }
  72.   }
  73.    
  74. }
  75. ?>
  76. //form input
  77. <div class="modal fade" id="tambah_tps">
  78.           <div class="modal-dialog modal-md">
  79.             <div class="modal-content">
  80.               <div class="modal-header">
  81.                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  82.                   <span aria-hidden="true">&times;</span></button>
  83.                 <h4 class="modal-title">Add TPS</h4>
  84.               </div>
  85.               <div class="modal-body">
  86.               <form enctype="multipart/form-data" method="post" name="form14" id="form14" action="<?php echo $FormAction; ?>" autocomplete="off">
  87.               <div class="box-body">
  88.               <div class="col-lg-6">
  89.                 <div class="form-group">
  90.                   <label>Nama Wilayah</label>
  91.                   <select class="form-control" name="name_region" id="name_region" style="width: 100%;" required>
  92.                   <option value="" disabled selected>- PILIH -</option>
  93.                     <option value="Indonesia">Indonesia</option>
  94.                   </select>
  95.                 </div>
  96.               </div>
  97.               <div class="col-lg-6">
  98.                 <div class="form-group">
  99.                   <label>Nama Provinsi</label>
  100.                   <select class="form-control select2" name="code_prov" id="code_prov" style="width: 100%;" required>
  101.                   <option value="" disabled selected>- PILIH -</option>
  102.                   <?php
  103.                   $no = 1;
  104.                   $query=mysql_query("SELECT DISTINCT code_region,name_region FROM master_region WHERE CHAR_LENGTH(code_region)='2' ORDER BY code_region asc");
  105.                   while ($row = mysql_fetch_assoc($query)):
  106.                   ?>
  107.                     <option value="<?php echo $row['code_region']; ?>"><?php echo $no++ ?>. <?php echo $row['name_region']; ?></option>
  108.                   <?php endwhile;?>
  109.                   </select>
  110.                 </div>
  111.               </div>
  112.               <div class="col-lg-6">
  113.                 <div class="form-group">
  114.                   <label>Nama Kabupaten/Kota</label>
  115.                   <select class="form-control select2" name="code_kab" id="code_kab" style="width: 100%;" required>
  116.                     <option value="">- PILIH PROVINSI -</option>
  117.                   </select>
  118.                 </div>
  119.               </div>
  120.               <div class="col-lg-6">
  121.                 <div class="form-group">
  122.                   <label>Nama Kecamatan</label>
  123.                   <select class="form-control select2" name="code_kec" id="code_kec" style="width: 100%;" required>
  124.                     <option value="">- PILIH KAB/KOTA -</option>
  125.                   </select>
  126.                 </div>
  127.               </div>
  128.               <div class="col-lg-6">
  129.                 <div class="form-group">
  130.                   <label>Nama Kelurahan/Desa</label>
  131.                   <select class="form-control select2" name="code_kel" id="code_kel" style="width: 100%;" required>
  132.                     <option value="">- PILIH KECAMATAN -</option>
  133.                   </select>
  134.                 </div>
  135.               </div>
  136.               <div class="col-lg-6">
  137.                 <div class="form-group">
  138.                   <label>Jumlah TPS</label>
  139.                   <input type="text" name="jumlah_tps" pattern="[0-9]{1,4}" title="Masukan angka" class="form-control" required>
  140.                 </div>
  141.               </div>
  142.              
  143.  
  144.          
  145.               </div>
  146.               <!-- /.box-body -->
  147.  
  148.               </div>
  149.               <div class="modal-footer">
  150.                 <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
  151.                 <button type="submit" class="btn btn-primary" id="btn_save">Save</button>
  152.                 <input type="hidden" name="id">
  153.                 <input type="hidden" name="code_region">
  154.                 <input type="hidden" name="name_prov">  
  155.                 <input type="hidden" name="name_kab">
  156.                 <input type="hidden" name="name_kec">
  157.                 <input type="hidden" name="name_kel">
  158.                 <input type="hidden" name="code_tps">
  159.                 <input type="hidden" name="name_tps">
  160.                 <input type="hidden" name="password">
  161.                 <input type="hidden" name="role">
  162.                         <input type="hidden" name="MM_insert" value="form14">
  163.               </div>
  164.             </form>
  165.             </div>
  166.             <!-- /.modal-content -->
  167.           </div>
  168.           <!-- /.modal-dialog -->
  169.         </div>
  170.         <!-- /.modal -->
Add Comment
Please, Sign In to add comment