초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
35
todos.php
Normal file
35
todos.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||||
|
||||
$mode = isset($_POST['mode']) ? $_POST['mode'] : '';
|
||||
$day = isset($_POST['day']) ? $_POST['day'] : '';
|
||||
$todo = isset($_POST['todo']) ? $_POST['todo'] : '';
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $mode === 'insert') {
|
||||
try {
|
||||
$sql = "INSERT INTO todos (day, todo) VALUES (:day, :todo)";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(':day', $day, PDO::PARAM_INT);
|
||||
$stmh->bindValue(':todo', $todo, PDO::PARAM_STR);
|
||||
$stmh->execute();
|
||||
echo json_encode(['status' => 'success']);
|
||||
} catch (PDOException $Exception) {
|
||||
echo json_encode(['status' => 'error', 'message' => $Exception->getMessage()]);
|
||||
}
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$day = isset($_GET['day']) ? $_GET['day'] : '';
|
||||
try {
|
||||
$sql = "SELECT todo FROM todos WHERE day = :day";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(':day', $day, PDO::PARAM_INT);
|
||||
$stmh->execute();
|
||||
$todos = $stmh->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo json_encode($todos);
|
||||
} catch (PDOException $Exception) {
|
||||
echo json_encode(['status' => 'error', 'message' => $Exception->getMessage()]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user