보안을 그리다, 훈이

[Web Hacking / PHP & MySQL] 게시판 구현 - read.php 본문

Programming/PHP & MySQL

[Web Hacking / PHP & MySQL] 게시판 구현 - read.php

HooNeee 2021. 4. 29. 21:07

게시판의 존재 목적 CRUD 중 이전 포스팅 때 구현한 Create에 이어 이번 포스팅에서는 Read에 대해 다뤄볼 것이다.

 

게시판에 업로드된 글을 읽을 수 있도록 read.php를 구현했다.

 

 

[read.php 소스코드]

<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>

    <style>
        .read_table {
            border: 1px solid #444444;
            margin-top: 30px;
        }

        .read_title {
            height: 45px;
            font-size: 23.5px;
            text-align: center;
            background-color: #3C3C3C;
            color: white;
            width: 1000px;
        }

        .read_id {
            text-align: center;
            background-color: #EEEEEE;
            width: 30px;
            height: 33px;
        }

        .read_id2 {
            background-color: white;
            width: 60px;
            height: 33px;
            padding-left: 10px;
        }

        .read_hit {
            background-color: #EEEEEE;
            width: 30px;
            text-align: center;
            height: 33px;
        }

        .read_hit2 {
            background-color: white;
            width: 60px;
            height: 33px;
            padding-left: 10px;
        }

        .read_content {
            padding: 20px;
            border-top: 1px solid #444444;
            height: 500px;
        }

        .read_btn {
            width: 700px;
            height: 200px;
            text-align: center;
            margin: auto;
            margin-top: 50px;
        }

        .read_btn1 {
            height: 50px;
            width: 100px;
            font-size: 20px;
            text-align: center;
            background-color: white;
            border: 2px solid black;
            border-radius: 10px;
        }

        .read_comment_input {
            width: 700px;
            height: 500px;
            text-align: center;
            margin: auto;
        }

        .read_text3 {
            font-weight: bold;
            float: left;
            margin-left: 20px;
        }

        .read_com_id {
            width: 100px;
        }

        .read_comment {
            width: 500px;
        }
    </style>
</head>

<body>
    <?php
    $connect = mysqli_connect('127.0.0.1', 'root', 'password', 'db_board');
    $number = $_GET['number'];  // GET 방식 사용
    session_start();
    $query = "select title, content, date, hit, id from board where number = $number";
    $result = $connect->query($query);
    $rows = mysqli_fetch_assoc($result);
    ?>

    <table class="read_table" align=center>
        <tr>
            <td colspan="4" class="read_title"><?php echo $rows['title'] ?></td>
        </tr>
        <tr>
            <td class="read_id">작성자</td>
            <td class="read_id2"><?php echo $rows['id'] ?></td>
            <td class="read_hit">조회수</td>
            <td class="read_hit2"><?php echo $rows['hit'] ?></td>
        </tr>


        <tr>
            <td colspan="4" class="read_content" valign="top">
                <?php echo $rows['content'] ?></td>
        </tr>
    </table>

    <!-- MODIFY & DELETE 추후 세션처리로 보완 예정 -->
    <div class="read_btn">
        <button class="read_btn1" onclick="location.href='./index.php'">목록</button>&nbsp;&nbsp;
        <button class="read_btn1" onclick="location.href='./modify.php?number=<?= $number ?>&id=<?= $_SESSION['userid'] ?>'">수정</button>&nbsp;&nbsp;
        <button class="read_btn1" onclick="location.href='./delete.php?number=<?= $number ?>&id=<?= $_SESSION['userid'] ?>'">삭제</button>
    </div>
</body>

</html>

 

read.php는 게시판 목록의 글을 통해 접속할 수 있으며 제목, 작성자, 조회수, 본문이 출력된다.

조회수(hit) 기능은 추후 구현하여 포스팅하도록 하겠다.

 

하단에는 목록 버튼, 수정 버튼, 삭제 버튼이 존재한다.

목록 버튼을 클릭하면 index.php로 이동하게 되며, 수정 버튼과 삭제 버튼은 현재 동작하지 않는다. 두 기능은 세션처리를 이용해 구현하여 포스팅할 예정이다.

 

기타 페이지와 다른점은 속성값(number)을 POST 방식이 아닌 GET 방식으로 가져오기 때문에 URL을 통해서도 접근할 수 있다.

ex) read.php?number=23

 

 

[read.php 결과]

read.php?number=1에 접속한 화면이다.

성공적으로 잘 출력되는 것을 볼 수 있지만.. 아직 해야할 게 산더미다ㅠㅠ

 

좀 더 힘내보자!

Comments