<?php
require_once("conn.php");

// membuka database
$db_connection = mysqli_connect($db_server, $db_username, $db_password);
mysqli_select_db($db_connection,$db_database );
if (!$db_connection) { echo "ERROR#".mysqli_error(); exit; }

$result = mysqli_query($db_connection,"DELETE FROM tokenpln");

// menerima data xml dan dimasukkan ke dalam variabel $dv_dataxml
if (isset($_POST["dv_dataxml"])) {$dv_dataxml=urldecode($_POST["dv_dataxml"]);} else {$dv_dataxml="";}

// proses pembacaan data XML
$dv_dataxml=str_replace('\"', '"', $dv_dataxml);
$dataxml = simplexml_load_string($dv_dataxml);

foreach($dataxml->csr_tokenpln as $data) {
    if ($data->nama!='') {
   // proses insert data ke mysql
   $ds_result=false; $ds_error=''; $ds_query='';
  
  
   $creation_ts=date('d-m-Y H:i:s');

   $ds_query.="insert into tokenpln ".
   "(`nama`, `kode_produk`)".
   "VALUES ".
   "("."'".addslashes($data->nama)."'".","."'".addslashes($data->kode_produk)."'".")";
   $ds_result = mysqli_query($db_connection,$ds_query);
   $ds_error = mysqli_error($db_connection);
   if (!$ds_error=='') { echo "ERROR#".$ds_error; mysqli_close($db_connection); mysqli_close($db_connection); exit; }
    }
}

// tutup database
mysqli_close($db_connection);
?>