<?php include ("inc/config.php");
 
if(isset($_REQUEST["term"])){  $sql = "SELECT * FROM `products` where quantity > 0 and name LIKE ?";
    
if($stmt = $mysqli->prepare($sql)){
 // Bind variables to the prepared statement as parameters
 $stmt->bind_param("s", $param_term);
 // Set parameters
 $param_term = $_REQUEST["term"] . '%' ;
 // Attempt to execute the prepared statement
 if($stmt->execute()){
   $result = $stmt->get_result();
   // Check number of rows in the result set
 if($result->num_rows > 0){

echo "<table >";
echo "<thead>";
echo "<tr class='t2'>";
echo "<th>Image</th>";
//echo "<th>code</th>";
echo "<th>name</th>";
echo "<th>Size</th>";
echo "<th>Items in store</th>";
echo "<th>Price</th>";
echo "<th>Release</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";

 // Fetch result rows as an associative array
 while($row = $result->fetch_array(MYSQLI_ASSOC)){
echo "<tr>";
echo "<form method='post' action=''>";
echo "<td><input type='hidden' name='code' value=".$row['code']." />";
echo "<img class='product-image' src='../product-images/".$row['image']."' /></td>";
// echo "<td>" . $row['code'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['size'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "<td>KSH. " . $row['price'] ."/= </td>";
echo "<td><button type='submit' class='btn-release'>Exchange</button> </td>";
echo "</form>";
echo "</tr>";
  
  }

  echo "</table>";
      } else{
                echo "<p class='no-results'>No matches found</p>";
            }
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        }
    }
     
    // Close statement
    $stmt->close();
}
 
// Close connection
$mysqli->close();
?>