aa21123a / customers.php
Funybubble's picture
make the backend php - Follow Up Deployment
84e853d verified
raw
history blame contribute delete
684 Bytes
```php
<?php
require_once 'config.php';
// JWT verification middleware
verifyToken();
// GET all customers
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$stmt = $pdo->query("SELECT * FROM customers");
$customers = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($customers);
}
// GET customer orders
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['customer_id'])) {
$customer_id = $_GET['customer_id'];
$stmt = $pdo->prepare("SELECT * FROM orders WHERE customer_email = (SELECT email FROM customers WHERE id = ?)");
$stmt->execute([$customer_id]);
$orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($orders);
}
?>
```