<?php
 
include 'dbconfig.php';
 
// Create connection
$nama=$_POST['nama'];
//$kodecab=$_POST['kodecab'];
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}



$tipe=$_POST['tipe'];
if ($tipe=='new')
{
    $kode=$_POST['kode'];
    $nama=$_nama['nama'];
    $sql=mysqli_query($conn, "insert into tbl_barang_bak (kode,nama) values ('$kode','$nama')" );
    return;
}
 
//$result["errorcode"]="0";
 
$sql = "SELECT id, kode, nama, harga,harga_beli FROM tbl_barang_bak where nama like '%".$nama."%' OR kode like '%".$nama."%' order by id desc";
 
$res = mysqli_query($conn, $sql);
 
$items = array();
 
if (mysqli_num_rows($res) > 0) {
 
    while($row = mysqli_fetch_object($res)){
 
        array_push($items, $row);
 
//$result["errorcode"] = "1";
 
    $result["data"] = $items;
 
}}
else
{
 
       $result["errormsg"] = "failed";
 
}
 
echo json_encode($result);
 
mysqli_close($conn);
 
?>
