<?php
/*====================== Database Connection Code Start Here ======================= */
// $dbc=mysqli_connect("localhost","juwakaco_231","@@!!jwaki#$%","juwakaco_pot");
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "root"); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME","point_of_sale"); // 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 80';
 
$recSql = mysqli_query($link,($query));
if(mysqli_num_rows($recSql)>0){
while($recResult = mysqli_fetch_assoc($recSql)) {
  $json_arr["id"] = "w5.php?id=".$recResult['id'];
  $json_arr["value"] = strtoupper($recResult['p_name']);
  $json_arr["label"] = strtoupper($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;
?>