ห้ามหลงมากดซื้อ.1
include"./config.php ";
@header("content-type:application/json;charset=utf-8");หห
@header("Access-Control-Allow-Origin: *");
@header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');
$content = @file_get_contents('php://input');
$json_data = @json_decode($content, true);
@$mode = trim($json_data['mode']);
if($_SERVER["REQUEST_METHOD"]=="POST"){
if($mode=="GET"){
@$branch_id = trim($json_data['branch_id']);
$strSQL ="";
if($branch_id != ""){
$strSQL ="SELECT*FROMtbl_branch WHERE branch_id = '".$branch_id ."' ";
}else{
$strSQL ="SELECT*FROMtbl_branch ORDER BYbranch_id ASC";
}
$sth= mysqli_query($conn,$strSQL);
$rows= array();
while($r= mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>$rows));
return0;
}elseif($mode=="POST"){ //Create
@$branch_name= trim($json_data['branch_name']);
if($branch_name== "" ){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_branch WHEREbranch_name = '".$branch_name."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"DUP","datas"=>NULL));
return0;
}else{
$strSQL= "INSERT INTOtbl_branch (branch_name) VALUES( '".$branch_name."' )";
if ($conn->query($strSQL) === TRUE) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}elseif($mode=="PUT"){
@$branch_id= trim($json_data['branch_id']);
@$branch_name= trim($json_data['branch_name']);
if($branch_name== ""|| $branch_id== ""){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_branch WHEREbranch_name = '".$branch_name."' AND branch_id <> '".$branch_id."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"DUP","datas"=>NULL));
return0;
}else{
$strSQL= "UPDATEtbl_branch SETbranch_name = '".$branch_name."' WHERE branch_id = '".$branch_id."' ";
if ($conn->query($strSQL) === TRUE) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}elseif($mode=="DELETE"){
@$branch_id= trim($json_data['branch_id']);
if($branch_id== "" ){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_real_product WHEREbranch_id = '".$branch_id."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"USED","datas"=>NULL));
return0;
}else{
$sql= "DELETEFROMtbl_branch WHERE branch_id= '".$branch_id."' ";
if ($conn->query($sql)) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
?>
include"./config.php ";
@header("content-type:application/json;charset=utf-8");หห
@header("Access-Control-Allow-Origin: *");
@header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');
$content = @file_get_contents('php://input');
$json_data = @json_decode($content, true);
@$mode = trim($json_data['mode']);
if($_SERVER["REQUEST_METHOD"]=="POST"){
if($mode=="GET"){
@$branch_id = trim($json_data['branch_id']);
$strSQL ="";
if($branch_id != ""){
$strSQL ="SELECT*FROMtbl_branch WHERE branch_id = '".$branch_id ."' ";
}else{
$strSQL ="SELECT*FROMtbl_branch ORDER BYbranch_id ASC";
}
$sth= mysqli_query($conn,$strSQL);
$rows= array();
while($r= mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>$rows));
return0;
}elseif($mode=="POST"){ //Create
@$branch_name= trim($json_data['branch_name']);
if($branch_name== "" ){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_branch WHEREbranch_name = '".$branch_name."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"DUP","datas"=>NULL));
return0;
}else{
$strSQL= "INSERT INTOtbl_branch (branch_name) VALUES( '".$branch_name."' )";
if ($conn->query($strSQL) === TRUE) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}elseif($mode=="PUT"){
@$branch_id= trim($json_data['branch_id']);
@$branch_name= trim($json_data['branch_name']);
if($branch_name== ""|| $branch_id== ""){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_branch WHEREbranch_name = '".$branch_name."' AND branch_id <> '".$branch_id."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"DUP","datas"=>NULL));
return0;
}else{
$strSQL= "UPDATEtbl_branch SETbranch_name = '".$branch_name."' WHERE branch_id = '".$branch_id."' ";
if ($conn->query($strSQL) === TRUE) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}elseif($mode=="DELETE"){
@$branch_id= trim($json_data['branch_id']);
if($branch_id== "" ){
echojson_encode(array("status"=>400,"message"=>"REQUIRE","datas"=>NULL));
return0;
}else{
$sql= "SELECT*FROMtbl_real_product WHEREbranch_id = '".$branch_id."' ";
$result= $conn->query($sql);
if ($result->num_rows> 0) {
echojson_encode(array("status"=>400,"message"=>"USED","datas"=>NULL));
return0;
}else{
$sql= "DELETEFROMtbl_branch WHERE branch_id= '".$branch_id."' ";
if ($conn->query($sql)) {
echojson_encode(array("status"=>200,"message"=>"SUCCESS","datas"=>NULL));
return0;
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
}
}
}
}else{
echojson_encode(array("status"=>400,"message"=>"ERROR","datas"=>NULL));
return0;
}
?>
กรุณาเข้าสู่ระบบเพื่อแสดงความคิดเห็น