-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_question.php
More file actions
37 lines (29 loc) · 974 Bytes
/
add_question.php
File metadata and controls
37 lines (29 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once __DIR__ . '/db_connect.php';
$title = $_POST['title'] ?? '';
$body = $_POST['body'] ?? '';
$author_id = $_POST['author_id'] ?? 0;
$keyword_id = $_POST['keyword_id'] ?? null;
if (empty($title) || empty($body) || empty($author_id)) {
echo json_encode(["status" => "error", "message" => "필수 입력 누락"]);
exit;
}
$sql = "INSERT INTO questions (title, body, author_id, keyword_id)
VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssis", $title, $body, $author_id, $keyword_id);
if ($stmt->execute()) {
if ($keyword_id !== null) {
$conn->query("
UPDATE keywords
SET question_count = question_count + 1
WHERE keyword_id = $keyword_id
");
}
echo json_encode(["status" => "success", "message" => "질문 등록 성공"]);
} else {
echo json_encode(["status" => "error", "message" => $conn->error]);
}
$stmt->close();
mysqli_close($conn);
?>