<?php
 
include 'dbconfig.php';
 
$tipe = $_POST['tipe'];

$kode = $_POST['kode'];
 
$nama = $_POST['nama'];
 
$harga_jual= $_POST['harga_jual'];

$harga_beli = $_POST['harga_beli'];

//$kode_cabang = $_POST['kode_cabang'];
$kode_cabang='HO';

 
//$idno = $_POST['idno'];

 
 
 
// Create connection
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
 
if ($tipe=='new')
{
$query = "insert into tbl_barang (kode_cabang,kode,nama,harga,harga_beli) values ('$kode_cabang','$kode','$nama','$harga_jual','$harga_beli') ";
} else{
$query = "update tbl_barang set harga='$harga_jual', harga_beli='$harga_beli' where kode='$kode'";
}

 
/* 
if ($id != "0"){
 
$query = "update toko_profile set nama_toko='".$nama_toko."',alamat_toko='".$alamat_toko."',nohp='".$nohp."' ";
 
}*/
 
$response = mysqli_query($conn, $query) or die('Error query:  '.$query);
 
//$lid = mysqli_insert_id($conn);
 
$result["message"]="ok";
 
//$result["lid"]="$lid";
 
if ($response == 1){
 
    echo json_encode($result);
 
}
 
else{
 
    $result["message"]="failed";
 
    echo json_encode($result);
 
}
 
?>
