<?php

/*
    API ACTION : CLIENT GAM << CHECKING >>
    API LIEN : https://www.gamgabon.com/api.custgam.check.php?tel=07149700
*/


#----------------------------------------------------------------------------------

// DONNEES EN GET
 
# - Présumé client
    $numclient = $_GET['tel']; 

	header('Content-type: text/plain');
	$json =[];
#---------------------------------------------------------------------------------- 

// CONNEXION A LA BDD

    # Etape 0 : Connexion à la bdd
	$servername = "185.98.131.91";
	$username = "gamga830897";
	$password = "ttwtaudsq0";
	$dbname = "gamga830897";
	// Create connection
	$conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
		$json["data_status"] = "Incorrect";
		die("Connection failed: " . $conn->connect_error);
	}
#----------------------------------------------------------------------------------

// TRAITEMENT

if(isset($numclient) && !empty($numclient))
{   
	$json["data_status"] = "Correct";
	$sql = "SELECT * FROM client_gam WHERE numclient = '$numclient'";
	$result = $conn->query($sql);
	
    if(mysqli_num_rows($result) > 0)
    { 
		$json["num_client_status"] = "Ancien";

    }
    else
    {
       $json["num_client_status"] = "Nouveau";
    }
}
else
{
    $json["data_status"] = "Incorrect";
} 


echo json_encode($json);

?>

