<?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#".mysql_error(); exit; }

$jml= mysqli_query($db_connection,"SELECT * FROM reseller");
$jumlah=mysqli_num_rows($jml);

// 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_reseller as $data) {
    if ($data->kode!='') {
   // proses insert data ke mysql
   $ds_result=false; $ds_error=''; $ds_query='';
  
  
   $creation_ts=date('d-m-Y H:i:s');
$result = mysqli_query($db_connection,"DELETE FROM reseller where kode='$data->kode'");
   	$ds_query.="insert into reseller ".
   "(`kode`,`nama`, `pin` ,`aktif`,`kode_upline`,`markup`,`kode_level`,`tgl_aktivitas`,`saldo`,`kode_area`,`poin`,`alamat`)".
   "VALUES ".
   "("."'".addslashes($data->kode)."'".","."'".addslashes($data->nama)."'".", "."'".addslashes($data->pin)."'".","."'".addslashes($data->aktif)."'".","."'".addslashes($data->kode_upline)."'".","."'".addslashes($data->markup)."'".","."'".addslashes($data->kode_level)."'".","."'".addslashes($data->tgl_aktivitas)."'".","."'".addslashes($data->saldo)."'".","."'".addslashes($data->kode_area)."'".","."'".addslashes($data->poin)."'".","."'".addslashes($data->alamat)."'".")";
   
   $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; }
    }
}

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