33 lines
1018 B
PHP
33 lines
1018 B
PHP
<?php
|
|
require_once '../db/config.php';
|
|
|
|
if (isset($_GET['sold_serial_id'])) {
|
|
$sold_serial_id = $_GET['sold_serial_id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare(
|
|
"SELECT p.name, p.model_number, p.part_number, p.description, p.image_url
|
|
FROM products p
|
|
JOIN sold_serials ss ON p.id = ss.product_id
|
|
WHERE ss.id = ?"
|
|
);
|
|
$stmt->execute([$sold_serial_id]);
|
|
$product = $stmt->fetch();
|
|
|
|
if ($product) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode($product);
|
|
} else {
|
|
header("HTTP/1.0 404 Not Found");
|
|
echo json_encode(['error' => 'Product not found']);
|
|
}
|
|
} catch (PDOException $e) {
|
|
header("HTTP/1.0 500 Internal Server Error");
|
|
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
|
|
}
|
|
} else {
|
|
header("HTTP/1.0 400 Bad Request");
|
|
echo json_encode(['error' => 'No serial ID provided']);
|
|
}
|