<?php
/*====================== Database Connection Code Start Here ======================= */
// $dbc=mysqli_connect("localhost", "ygrwxiok_ane", "@@@5342@@qneaWR","ygrwxiok_pos");
			//	 $dbc=mysqli_connect("localhost", "ygrwxiok_demo", "@@@gtwWbg678!","ygrwxiok_point_of_sale");
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "txjdsese_dhk"); // set database user
define ("DB_PASS","@@@gtwWbg698!SDHK"); // set database password
define ("DB_NAME","txjdsese_pos"); // set database name

$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS,DB_NAME) or die("Couldn't make connection.");
//$db = mysqli_select_db(DB_NAME, $link) or die("Couldn't select database");
// $dbc=mysqli_connect("localhost", "mulberr3_qen", "@@@5342@@qne#&!#","mulberr3_spm");
/*====================== Database Connection Code End Here ========================== */

// Here, we will get user input data and trim it, if any space in that user input data
$user_input = trim($_REQUEST['term']);

// Define two array, one is to store output data and other is for display
$display_json = array();
$json_arr = array();
 

$user_input = preg_replace('/\s+/', ' ', $user_input);

$query = 'SELECT p_name, product_id as id FROM products  WHERE p_name LIKE "%'.$user_input.'%" order by p_name limit 50';
 
$recSql = mysqli_query($link,($query));
if(mysqli_num_rows($recSql)>0){
while($recResult = mysqli_fetch_assoc($recSql)) {
  $json_arr["id"] = "name_c.php?id=".$recResult['id'];
  $json_arr["value"] = $recResult['p_name'];
  $json_arr["label"] = $recResult['p_name'];
  array_push($display_json, $json_arr);
}
} else {
  $json_arr["id"] = "#";
  $json_arr["value"] = "";
  $json_arr["label"] = "No Result Found !";
  array_push($display_json, $json_arr);
}
 
	
$jsonWrite = json_encode($display_json); //encode that search data
print $jsonWrite;
?>