24 lines
625 B
PHP
24 lines
625 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
echo json_encode(['success' => false, 'error' => 'Invalid method']);
|
|
exit;
|
|
}
|
|
|
|
$content = $_POST['content'] ?? '';
|
|
|
|
if (empty($content)) {
|
|
echo json_encode(['success' => false, 'error' => 'Content is empty']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO snippets (content) VALUES (?)");
|
|
$stmt->execute([$content]);
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|