I want to make API for android. I'm working on a form in php that inserts data to MySQL, but before the data is inserted there is a field that must be checked in another table before inserting. If this value exist in the other table, then the data is inserted in the main table, if not, then data is not inserted.
This Is my php
<?php
if($_SERVER['REQUEST_METHOD']=='POST') {
$response = array();
$username = $_POST['username'];
$SN = $_POST['SN'];
require_once('dbConnect.php');
$sql = "SELECT * FROM produk WHERE SN ='$SN'";
$check = mysqli_fetch_array(mysqli_query($con,$sql));
if(isset($check)){
$response["value"] = 0;
$sql = "INSERT INTO farm (username,SN) VALUES('$username','$SN')";
$response["message"] = "Successful";
echo json_encode($response);
} else {
$response["value"] = 1;
$response["message"] = "oops! Try Again";
echo json_encode($response);
}
mysqli_close($con);
} else {
$response["value"] = 0;
$response["message"] = "oops! Try Again";
echo json_encode($response);
}
?>
How solve the code?