<?php
require_once('includes/load.php');

if (isset($_GET['partNumber'])) {
  $partNumber = $db->escape($_GET['partNumber']);

  // Cari informasi produk berdasarkan nomor bagian
  $product = find_product_by_part_number($partNumber);

  if ($product) {
    $productInfo = "<strong>Name:</strong> {$product['name']}<br>";
    $productInfo .= "<strong>Sale Price:</strong> {$product['sale_price']}<br>";
  } else {
    $productInfo = "Product not found.";
  }

  echo $productInfo;
} else {
  echo "Invalid request.";
}

function find_product_by_part_number($part_number) {
    global $db;

    $sql = "SELECT * FROM products WHERE part_number = '{$part_number}'";
    $result = $db->query($sql);

    if ($result && $db->num_rows($result) > 0) {
        $product = $db->fetch_assoc($result);
        return $product;
    } else {
        return false;
    }
}
?>
