Files
egbim_homepage/egbim/bbs/descope_qa_comment_update.php
T
2026-07-23 16:15:57 +09:00

38 lines
1.4 KiB
PHP

<?php
date_default_timezone_set('Asia/Seoul');
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../skin/member/basic/descope_session.php';
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$loginId = $_SESSION['user']['loginIds'][0] ?? '';
$commentId = (int)($_POST['commentId'] ?? 0);
$newComment = trim($_POST['comment'] ?? '');
if ($commentId < 1 || $newComment === '') {
echo json_encode(['status'=>'fail','message'=>'잘못된 요청']); exit;
}
try {
$pdo = new PDO("mysql:host=db;dbname=egbim;charset=utf8mb4",
'egbim','baron3840!!',
[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$pdo->exec("SET time_zone = '+09:00'");
// 본인 댓글인지 확인
$st = $pdo->prepare("SELECT commenter FROM qa_comments WHERE comment_id=?");
$st->execute([$commentId]);
$row = $st->fetch();
if (!$row) { echo json_encode(['status'=>'fail','message'=>'존재하지 않는 댓글']); exit; }
if ($row['commenter'] !== $loginId) {
echo json_encode(['status'=>'fail','message'=>'본인 댓글만 수정 가능']); exit;
}
// 업데이트
$up = $pdo->prepare("UPDATE qa_comments SET content=?, updated_at=NOW() WHERE comment_id=?");
$up->execute([$newComment, $commentId]);
echo json_encode(['status'=>'ok']);
} catch(Exception $e) {
echo json_encode(['status'=>'fail','message'=>$e->getMessage()]);
}