본문 바로가기

프로그래밍/게시판 만들기

글 작성 write.php write_action.php

 

프론트 엔드(?)

write.php

<!DOCTYPE>

<html>
<head>
        <meta charset = 'utf-8'>
        <title>글 작성</title>
        <style>
                table.table2{
                        border-collapse: separate;
                        border-spacing: 1px;
                        text-align: left;
                        line-height: 1.5;
                        border-top: 1px solid #ccc;
                        margin : 20px 10px;
                }
                table.table2 tr {
                         width: 50px;
                         padding: 10px;
                        font-weight: bold;
                        border-bottom: 1px solid #ccc;
                }
                table.table2 td {
                         width: 120px;
                         border-bottom: 1px solid #ccc;
                }

        </style>
</head>

<body>
  <?php
  session_start();
  if(!isset($_SESSION['userid'])){
    ?>
    <script type="text/javascript">
      alert("로그인 먼저 해주세요");
      location.replace('login.php');
    </script>
    <?php
  }
   ?>
        <form method = "post" action = "write_action.php">
        <table  style="padding-top:50px" align = center width=750 border=0 cellpadding=2 >
                <tr>
                <td height=20 align= center bgcolor=#ccc><font color=white> 글쓰기</font></td>
                </tr>
                <tr>
                <td bgcolor=white>
                <table class = "table2">
                        <tr>
                        <td>작성자</td>
                        <td><input type = "hidden" name = "name" value="<?php echo $_SESSION['userid']; ?>" size=20><?php echo $_SESSION['userid']; ?></td>
                        </tr>

                        <tr>
                        <td>제목</td>
                        <td><input type = "text" name = "title" size=60></td>
                        </tr>

                        <tr>
                        <td>내용</td>
                        <td><textarea name = "content" cols="85" rows="15"></textarea></td>
                        </tr>
                        </table>

                        <center>
                        <input type = "submit" value="작성">
                        </center>
                </td>
                </tr>
        </table>
        </form>
</body>
</html>

 

백엔드(?)

write_action.php

<?php
               $con = mysqli_connect("localhost", "root", "----", "----") or die("fail");

               $id = $_POST['name'];                      //Writer
               $title = $_POST['title'];                  //Title
               $content = $_POST['content'];              //Content
               $date = date('Y-m-d', time());            //Date

               $URL = 'index.php';                   //return URL


               $query = "insert into board (number,title, content, date, hit, id, password)
                       values(null,'$title', '$content', '$date',0, '$id', '0')";


               $result = mysqli_query($con,$query);
               if($result){
?>                  <script>
                       alert("<?php echo "글이 등록되었습니다."?>");
                       location.replace("<?php echo $URL?>");
                   </script>
<?php
               }
               else{
                       echo "FAIL";
               }

               mysqli_close($con);
?>

'프로그래밍 > 게시판 만들기' 카테고리의 다른 글

게시판과 회원정보 DB  (0) 2019.11.16
로그아웃  (0) 2019.11.16
글 보기 view.php  (0) 2019.11.16
로그인 페이지 login.php login_action.php  (0) 2019.11.16
회원가입 페이지 join.php, join_action.php  (0) 2019.11.15