-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_process.php
More file actions
47 lines (40 loc) · 1.55 KB
/
write_process.php
File metadata and controls
47 lines (40 loc) · 1.55 KB
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
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<title>글 작성하기 결과</title>
<link rel="stylesheet" href="/CodeConnect/css/write_process.css">
</head>
<body>
<div class="container">
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit();
}
$category_id = $_POST['category'];
$title = $_POST['title'];
$content = $_POST['content'];
// 데이터베이스 연결 설정
include 'connect.php';
// 현재 사용자의 username을 기반으로 author_id 가져오기
$username = $_SESSION['username'];
$query = "SELECT id FROM users WHERE username = '$username'";
$result = $conn->query($query);
$user = $result->fetch_assoc();
$author_id = $user['id'];
// 글 삽입 쿼리
$insert_query = "INSERT INTO posts (category_id, author_id, title, content) VALUES ('$category_id', '$author_id', '$title', '$content')";
if ($conn->query($insert_query) === TRUE) {
echo "<p>글 작성이 완료되었습니다.</p>";
echo '<button onclick="window.location.href=\'mainboard.php\'">메인보드로 돌아가기</button>';
} else {
echo "오류: " . $conn->error;
}
$conn->close();
}
?>
</div>
</body>
</html>