<?php

    $request_json=$_REQUEST["data"];
    $arr = json_decode($request_json, true);
    $mobile = $arr["contact"];
    $table = $arr["table"];
    //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);
        if($table == "staff"){
            $qry = "select staff_id, name, mobile, shop_id, password from master_staff where mobile=?";
        }
        if($table == "shop"){
            $qry = "select shop_id, shop_name, mobile, password, shop_id from master_shop where mobile = ?";
        }
        $stmt = $pdo->prepare($qry);
        $stmt->execute([$mobile]); 
        $user = $stmt->fetch();
        
        $jsontext = "{";
        foreach($user as $key => $value) {
            $jsontext .= "\"".addslashes($key)."\":\"".addslashes($value)."\",";
        }
        $jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
        $jsontext .= "}";
        
        echo $jsontext;
    }catch(PDOException $e) {
        echo $sql . "err" . $e->getMessage();
    }
    $pdo = null;
    
?>