
우선 테이블을 먼저 만들어야겠죵
CREATE TABLE board (
num INT AUTO_INCREMENT PRIMARY KEY,
title CHAR(150) NOT NULL,
content text NOT NULL,
day CHAR(20) NOT NULL,
count INT(11) NOT NULL,
name CHAR(20),
file_id VARCHAR(255),
notice tinyint(1) DEFAULT 0);
자료형이 CHAR이었다가 VARCHAR였다가 아주 제멋대로인 이유는
여러개의 블로그를ㄹ 참조했기 때문인데요.....
님들은 이렇게 하지마세요
저는 조회수도 보여지게 하고싶어서 count 컬럼하구
파일 업로드 기능도 구현할거기때문에! file_id와
공지사항 기능도 넣고싶어서 notice 컬럼도 넣었답니당
HTML 폼 만들어주기~~
[ board.php ]
<?php
include 'lib.php'
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>게시판</title>
</head>
<body>
<?php
if (isset($_SESSION['id'])) { ?>
<h1><a href="board.php" style="text-decoration:none">게시판</a></h1>
<table border=1>
<thead>
<tr>
<th width=50>번호</th>
<th width=400>제목</th>
<th width=80>작성자</th>
<th width=100>작성일</th>
<th width=50>조회수</th>
</tr>
</thead>
<tbody>
<?php
$notice_sql = "SELECT * FROM board WHERE notice = 1 ORDER BY num DESC LIMIT 3;";
$sql = "SELECT * FROM board WHERE notice = 0 ORDER BY num DESC;";
$notice_result = mysqli_query($conn, $notice_sql);
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($notice_result)) {
echo "<tr style='background: #ffeeba;'>";
echo "<td>".$row['num']."</td>";
echo "<td><a href='view.php?num=".$row['num']."'>".$row['title']."</a></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['day']."</td>";
echo "<td>".$row['count']."</td>";
echo "</tr>";
}
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['num']."</td>";
echo "<td><a href='view.php?num=".$row['num']."'>".$row['title']."</a></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['day']."</td>";
echo "<td>".$row['count']."</td>";
echo "</tr>";
}
mysqli_close($conn);
?>
</tbody>
</table>
<br>
<form method="POST" action="search.php">
<select name="type">
<option value="title">제목</option>
<option value="name">작성자</option>
</select>
<input type="text" name="search" style="width:570px">
<input type="submit" value="검색하기">
</form>
<br>
<button type="button" onclick="location.href='write.php'">글 작성</button>
<button type="button" onclick="location.href='index.php'">메인화면</button>
<?php } else {
echo "<script>alert('회원만 접근할 수 있는 게시판입니다'); window.location.href='index.php';</script>";
}
?>
</body>
</html>
로그인 하지 않으면 (세션값으로 id 안넘어오면) 아예 게시판 접근도 못하게 막아버렸고요
게시판 리스트 맨 위에 세 개는 항상 공지사항이 뜰 수 있게 만들었어용
공지사항인거 알아보기 쉽게 노랑색으로 하이라이트도 줌
우하하
'모의해킹' 카테고리의 다른 글
| PHP + MySQL 게시판 제작 - 게시글 작성 (+파일 업로드) (0) | 2026.02.16 |
|---|---|
| PHP + MySQL 게시판 제작 - 게시판 검색 기능 (0) | 2026.02.16 |
| PHP + MySQL 게시판 제작 - 로그인 & 로그아웃 (0) | 2026.02.16 |
| PHP + MySQL 게시판 제작 - 회원가입 (0) | 2026.02.16 |
| SQL Injection (Get/Search) (0) | 2025.07.04 |