<?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", "dhdogzbe_dubo"); // set database user
define ("DB_PASS","@@FRE@W21aswdubo!@@vB4546g@@!"); // set database password
define ("DB_NAME","dhdogzbe_dubois"); // set database name
//mysqli_connect('localhost','dhdogzbe_dubo','@@FRE@W21aswdubo!@@vB4546g@@!','dhdogzbe_dubois');
$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 product  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;
?>