<?php

    $request_json=$_REQUEST["data"];
    $arr = json_decode($request_json, true);
    $mobile = $arr["contact"];
    //include 'common/connection.php';
    $servername = "localhost";
    $username = "finstech_sales";
    $password = "SalesApp@123";
    $dbname = "finstech_salesapp";
    
    
    try {
        $pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        $stmt = $pdo->prepare("select * from b2c_ustomer where contact = ?");
        $stmt->execute([$mobile]); 
        $user = $stmt->fetch();
        if($user > 0){
            $jsontext = "{";
            foreach($user as $key => $value) {
                $jsontext .= "\"".addslashes($key)."\":\"".addslashes($value)."\",";
            }
            $jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
            $jsontext .= "}";
        }else{
            $jsontext = "{\"response\":\"nodata\"}";
        }
        
        echo $jsontext;
    }catch(PDOException $e) {
        echo $sql . "err" . $e->getMessage();
    }
    $pdo = null;
    
?>