31 lines
759 B
PHP
31 lines
759 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
if (!isset($_GET['course_id'])) {
|
|
echo json_encode(['error' => 'Course ID is required.']);
|
|
exit;
|
|
}
|
|
|
|
$courseId = filter_input(INPUT_GET, 'course_id', FILTER_VALIDATE_INT);
|
|
|
|
if ($courseId === false) {
|
|
echo json_encode(['error' => 'Invalid Course ID.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM courses WHERE id = ?");
|
|
$stmt->execute([$courseId]);
|
|
$course = $stmt->fetch();
|
|
|
|
if ($course) {
|
|
echo json_encode($course);
|
|
} else {
|
|
echo json_encode(['error' => 'Course not found.']);
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo json_encode(['error' => 'Database error: ' . $e->getMessage()]);
|
|
}
|