kura2yamato

insert banyak tps

Aug 15th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. <?php
  2. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form14")) {
  3.         $data =  $_POST['jumlah_tps'];
  4.  
  5.         $id = autonumber("tps", "id", 1, "");      
  6.         $code_region = 1;
  7.         $name_region = $_POST['name_region'];
  8.  
  9.         $code_prov = $_POST['code_prov'];
  10.         $row1 = mysql_fetch_assoc(mysql_query("select * from master_region where code_region='$code_prov'"));
  11.         $name_prov = $row1['name_region'];
  12.  
  13.         $code_kab = $_POST['code_kab'];
  14.         $row2 = mysql_fetch_assoc(mysql_query("select * from master_region where code_region='$code_kab'"));
  15.         $name_kab = $row2['name_region'];
  16.        
  17.         $code_kec = $_POST['code_kec'];
  18.         $row3 = mysql_fetch_assoc(mysql_query("select * from master_region where code_region='$code_kec'"));
  19.         $name_kec = $row3['name_region'];
  20.  
  21.         $code_kel = $_POST['code_kel'];
  22.         $row4 = mysql_fetch_assoc(mysql_query("select * from master_region where code_region='$code_kel'"));
  23.         $name_kel = $row4['name_region'];
  24.         $role = "CHECKER";
  25.  
  26.         mysql_select_db($name_database, $database);
  27.         for($i=0;$i<$data;$i++) {
  28.             $code_tps = autostring("tps","code_tps",$code_kel,4,$code_kel.".");
  29.             $name_tps = substr($code_tps,-4);
  30.             $password = $code_tps;
  31.            
  32.             $code_tps2 =  $code_tps.".".sprintf("%04s",$i);
  33.  
  34.             $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)",
  35.                   GetSQLValueString($id, "text"),
  36.                   GetSQLValueString($code_region, "text"),
  37.                   GetSQLValueString($name_region, "text"),
  38.                   GetSQLValueString($code_prov, "text"),
  39.                   GetSQLValueString($name_prov, "text"),
  40.                   GetSQLValueString($code_kab, "text"),
  41.                   GetSQLValueString($name_kab, "text"),
  42.                   GetSQLValueString($code_kec, "text"),
  43.                   GetSQLValueString($name_kec, "text"),
  44.                   GetSQLValueString($code_kel, "text"),
  45.                   GetSQLValueString($name_kel, "text"),
  46.                   GetSQLValueString($code_tps2, "text"),
  47.                   GetSQLValueString($name_tps, "text"),
  48.                   GetSQLValueString($password, "text"),
  49.                   GetSQLValueString($role, "text"));
  50.  
  51.             $Result1 = mysql_query($insertSQL, $database) or die("sql:$insertSQL|".mysql_error());  
  52.         }
  53.         echo '<script>alert("Data berhasil dibuat"); location.href="tps"</script>';
  54.    
  55. }
Add Comment
Please, Sign In to add comment