javascript - how to insert array as json format into database using php my sqli -


guy's need help. have array , populate array json.stringify , want insert array database. have try make code wont work. don't know why.. hope can me out of problem

this code

$(document).ready(function(){  $("#submit-file").click(function(){          var myfile = $("#files")[0].files[0];          var json = papa.parse(myfile,               {              skipemptylines: true,              complete: function(results) {              var serialize = json.stringify(results);              $.ajax({                  type: "post",                  url: "../php/tagihan/save_data.php",                  data: serialize,                  cache: false,                  success: function(data) {  					              }          });          }      });    });  });
<?php  include('../../connections/koneksi.php');    // reading json file  $array = json_decode( $_post['array'] );    //converting json object php associative array  $data = json_decode($array, true);    // processing array of objects  foreach ($data $user) {      $kode = $user[0];      $sloc = $user[1];      $move = $user[2];      $id = $user[3];  	$date = $user[4];      $netto = $user[5];      $unit = $user[6];      $payroll = $user[7];      $uses = $user[8];      // preparing statement insert query      $st = mysqli_prepare($connection, 'insert wjm (kode, sloc, move, id, date, netto, unit, payroll, uses) values (?, ?, ?, ?, ?, ?, ?, ?, ?)');        // bind variables insert query params      mysqli_stmt_bind_param($st, 'ssss', $kode, $sloc, $move, $id, $date, $netto, $unit, $payroll, $uses);        // executing insert query      mysqli_stmt_execute($st);  }    ?>  //koneksi.php  <?php    $server = "localhost";  $user = "root";  $password = "";  $nama_database = "silo";    $db = mysqli_connect($server, $user, $password, $nama_database);    if( !$db ){      die("gagal terhubung dengan database: " . mysqli_connect_error());  }    ?>

i adding connection php code. sorry when code messy. try make far know that.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -