1. create/createBoard.php
<?php
include '../connect/connect.php';
$sql = "CREATE TABLE studyBoard (";
$sql .= "studyBoardID int(10) unsigned NOT NULL AUTO_INCREMENT,";
$sql .= "studyMemberID int(10) unsigned NOT NULL,";
$sql .= "boardTitle varchar(50) NOT NULL,";
$sql .= "boardContent longtext NOT NULL,";
$sql .= "boardView int(10) unsigned NOT NULL,";
$sql .= "regTime int(15) unsigned NOT NULL,";
$sql .= "PRIMARY KEY (studyBoardID)) CHARSET=utf8";
$result = $connect -> query($sql);
if($result){
echo "Create Board Complete";
} else {
echo "Create Board False";
}
?>
2. board.php
3. boardWrite.php
4. boardWriteSave.php
<?php
include "../connect/connect.php";
include "../connect/session.php";
include "../connect/sessionCheck.php";
$boardTitle = $_POST['boardTitle'];
$boardContent = $_POST['boardContent'];
$boardTitle = $connect -> real_escape_string($boardTitle);
$boardContent = $connect -> real_escape_string($boardContent);
$boardView = 0;
$regTime = time();
$memberID = $_SESSION['studyMemberID'];
$sql = "INSERT INTO studyBoard(studyMemberID, boardTitle, boardContent, boardView, regTime) VALUES('$memberID', '$boardTitle', '$boardContent', '$boardView', '$regTime')";
$result = $connect -> query($sql);
// if($result){
// echo "good";
// } else {
// echo "bad";
// }
?>
<script>
location.href="board.php";
</script>
5. board.php 파일에 게시 목록 보여주기 및 클릭시 게시글 보여주기
<?php
$sql = "SELECT b.studyBoardID, b.boardTitle, m.youName, b.boardView, b.regTime FROM studyBoard b JOIN studyMember m ON (m.studyMemberID = b.studyMemberID) ORDER BY studyBoardID";
$result = $connect -> query($sql);
if($result){
$count = $result -> num_rows;
if($count > 0){
for($i=1; $i<=$count; $i++){
$boardInfo = $result -> fetch_array(MYSQLI_ASSOC);
echo "<tr>";
echo "<td>".$boardInfo['studyBoardID']."</td>";
echo "<td><a href='boardView.php'>".$boardInfo['boardTitle']."</a></td>";
echo "<td>".$boardInfo['youName']."</td>";
echo "<td>".date('Y-m-d', $boardInfo['regTime'])."</td>";
echo "<td>".$boardInfo['boardView']."</td>";
echo "</tr>";
}
}
}
?>