<?php
 
include 'dbconfig.php';
 
$nama_toko = $_POST['nama_toko'];
 
$alamat_toko = $_POST['alamat_toko'];
 
$no_hp_toko= $_POST['no_hp_toko'];

$id = $_POST['id'];
 
// Create connection
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}
 
/* grab the posts from the db */

$query0 = "delete from toko_profile";
$response2 = mysqli_query($conn, $query0) or die('Error query:  '.$query0);

$query = "insert into toko_profile (nama_toko, alamat_toko, no_hp_toko) values('".$nama_toko."','".$alamat_toko."','".$no_hp_toko."')";
 
/* 
if ($id != "0"){
 
$query = "update toko_profile set nama_toko='".$nama_toko."',alamat_toko='".$alamat_toko."',no_hp_toko='".$no_hp_toko."' ";
 
}*/
 
$response = mysqli_query($conn, $query) or die('Error query:  '.$query);
 
$lid = mysqli_insert_id($conn);
 
$result["errormsg"]="Success";
 
$result["lid"]="$lid";
 
if ($response == 1){
 
    echo json_encode($result);
 
}
 
else{
 
    $result["errormsg"]="Fail";
 
    echo json_encode($result);
 
}
 
?>
