board_write.php
<form id="boardwrite" name="boardwrite" method="POST" action="board_write_ok.php">
<table class="table board_news nborder">
<tr> <!-- STATUS REVISION DATE -->
<th class="text_white">TITLE</th>
<td class="text_white"><input name="title" id="title" type="text" placeholder="TITLE"></td>
</tr>
<tr>
<th class="text_white">CONTENT</th>
<td class="text_white"><textarea name="content" id="content" cols="30" rows="10" placeholder="CONTENT"></textarea></td>
</tr>
<tr>
<th class="text_white">STATUS</th>
<td class="text_white"><input name="link" id="link" type="text" placeholder="LINK"></td>
</tr>
<tr>
<th class="text_white">DOCUMENT NUMBER</th>
<td class="text_white"><input name="dnum" id="dnum" type="text" placeholder="DOCUMENT NUM"></td>
</tr>
<tr>
<th class="text_white">CATEGORY</th>
<td class="text_white"><input name="cat" id="cat" type="text" placeholder="CATEGORY"></td>
</tr>
<tr>
<th class="text_white">PASSWORD</th>
<td class="text_white"><input name="pw" id="pw" type="password" placeholder="pw"></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">WRITE</button></td>
</tr>
</table>
</form>
<script>
function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");
if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}
document.boardwrite.submit();
}
</script>
db.php
<?php
header('Content-Type: text/html; charset=utf-8'); // utf-8인코딩
// 데이터베이스 연결 설정
// $host = "localhost";
// $username = "your_username";
// $password = "your_password";
// $dbname = "your_dbname";
$db = new mysqli($host, $username ,$password ,$dbname);
$db->set_charset("utf8");
function mq($sql)
{
global $db;
return $db->query($sql);
}
board_write_ok.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
$title = $_POST['title'];
$content = $_POST['content'];
$link = $_POST['link'];
$dnum = $_POST['dnum'];
$cat = $_POST['cat'];
$pw = $_POST['pw'];
//$date = now();
$sql = mq("insert into board_news (title, content, link, dnum, cat) values ('".$title."', '".$content."', '".$link."', '".$dnum."', '".$cat."');");
if ($sql){
echo "<script>alert('SEND COMPLETE.');window.location.replace('board_list.php');</script>";
}else{
echo "<script>alert('FAILED.');window.location.replace('board_list.php');</script>";
}
?>
board_list.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
?>
<table class="table board_news">
<tr>
<th class="text_white left">#</th>
<th class="text_white">TITLE</th>
<th class="text_white">WRITER</th>
<th class="text_white right">DATE</th>
</tr>
<!--FORUM STANDARD STATUS REVISION DATE -->
<?
$sql = mq("select * from board_news order by id desc;");
$n=1;
while ($board = $sql->fetch_array()) {
?>
<tr>
<td class="pt-3 left text_white left"><?php echo $n; ?></td>
<td class="pt-3 text_white"><a href="board_view.php?idx=<?= $board['id'] ?>" target="_self"><?php echo $board['title']; ?></a></td>
<td class="text_white center">관리자</td>
<td class="text_white right"><?php echo $board['date']; ?></td>
</tr>
<?
$n=$n+1;
}
?>
<tr><td colspan="3">
<button class="btn right" onclick="location.href='board_write.php';">WRITE</button></td>
</tr>
</table>
board_view.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
$idx = $_GET['idx'];
$sql = mq("SELECT * FROM board_news where id = ".$idx.";");
$news = $sql->fetch_array();
?>
<form id="boardwrite" name="boardwrite" method="POST" action="board_write_ok.php">
<table class="table board_news">
<tr> <!-- STATUS REVISION DATE Document Num DOCUMENT NUM-->
<th class="text_white" style="border:none !important;">TITLE</th>
<td class="text_white left" style="border:none !important;"><?= $news['title'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">CONTENT</th>
<td class="text_white left" style="border:none !important;"><?= $news['content'] ?></textarea></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">STATUS</th>
<td class="text_white left" style="border:none !important;"><?= $news['link'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">DOCUMENT NUMBER</th>
<td class="text_white left" style="border:none !important;"><?= $news['dnum'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">CATEGORY</th>
<td class="text_white left" style="border:none !important;"><?= $news['cat'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">REVISION DATE</th>
<td class="text_white left" style="border:none !important;"><?= $news['date'] ?></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="location.href='board_list.php';">LIST</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_del.php?idx=<?=$idx?>'">DELETE</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_mod.php?idx=<?=$idx?>'">MODIFY</button></td>
</tr>
</table>
</form>
<script>
function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");
if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}
document.boardwrite.submit();
}
</script>
board_mod.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
$idx = $_GET['idx'];
$sql = mq("SELECT * FROM board_news where id = ".$idx.";");
$news = $sql->fetch_array();
?>
<form id="boardwrite" name="boardwrite" method="POST" action="board_mod_ok.php">
<input type="hidden" name="idx" id="idx" value="<?=$news['id']?>">
<table class="table board_news nborder">
<!-- STATUS REVISION DATE -->
<tr>
<th class="text_white">TITLE</th>
<td class="text_white"><input name="title" id="title" type="text" value="<?= $news['title'] ?>"></td>
</tr>
<tr>
<th class="text_white">CONTENT</th>
<td class="text_white"><textarea name="content" id="content" cols="30" rows="10"><?= $news['content'] ?></textarea></td>
</tr>
<tr>
<th class="text_white">STATUS</th>
<td class="text_white"><input name="link" id="link" type="text" value="<?= $news['link'] ?>"></td>
</tr>
<tr>
<th class="text_white">DOCUMENT NUMBER</th>
<td class="text_white"><input name="dnum" id="dnum" type="text" value="<?= $news['dnum'] ?>"></td>
</tr>
<tr>
<th class="text_white">CATEGORY</th>
<td class="text_white"><input name="cat" id="cat" type="text" value="<?= $news['cat'] ?>"></td>
</tr>
<tr>
<th class="text_white">PASSWORD</th>
<td class="text_white"><input name="pw" id="pw" type="password" value=""></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">MODIFY</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_list.php';">LIST</button></td>
</tr>
</table>
</form>
<script>
function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");
if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}
document.boardwrite.submit();
}
</script>
board_mod_ok.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
$idx = $_POST['idx'];
$title = $_POST['title'];
$content = $_POST['content'];
$link = $_POST['link'];
$dnum = $_POST['dnum'];
$cat = $_POST['cat'];
$pw = $_POST['pw'];
$sql = mq("update board_news set title='".$title."', content='".$content."', link='".$link."', dnum='".$dnum."', cat='".$cat."' where id=".$idx.";");
if ($sql){
echo "<script>alert('UPDATE COMPLETE.');window.location.replace('board_list.php');</script>";
}else{
echo "<script>alert('UPDATE FAILED.');window.location.replace('board_list.php');</script>";
}
?>
board_del.php
<?php
$idx = $_GET['idx'];
?>
<form id="boardwrite" name="boardwrite" method="POST" action="board_del_ok.php">
<input type="hidden" name="idx" id="idx" value="<?=$idx?>">
<table class="table board_news nborder">
<tr>
<th class="text_white">ADMIN-ID</th>
<td class="text_white"><input name="adminid" id="adminid" type="text" placeholder="admin id"></td>
</tr>
<tr>
<th class="text_white">ADMIN-PASSWORD</th>
<td class="text_white"><input name="adminpw" id="adminpw" type="password" placeholder="admin password"></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">ADMIN CONFIRM</button></td>
</tr>
</table>
</form>
<script>
function confirm() {
var adminid = document.getElementById("adminid");
var adminpw = document.getElementById("adminpw");
if (adminid.value == '') {
alert("Please Insert ID.");
adminid.focus();
return false;
}
if (adminpw.value == '') {
alert("Please Insert PASSWORD.");
adminpw.focus();
return false;
}
document.boardwrite.submit();
}
</script>
board_del_ok.php
<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";
$idx = $_POST['idx'];
$adminid = $_POST['adminid'];
$adminpw = $_POST['adminpw'];
if ($adminid == '**' && $adminpw == '**'){
$sql = mq("delete from board_news where id=".$idx.";");
if ($sql){
echo "<script>alert('DELETE COMPLETE.');window.location.replace('board_list.php');</script>";
}else{
echo "<script>alert('DELETE FAILED.');window.location.replace('board_list.php');</script>";
}
} else {
echo "<script>alert('PLEASE CHECK ADMIN-SIGN-IN.');window.location.replace('board_list.php');</script>";
}
?>
myfunc.php
<?php
header('Content-Type: text/html; charset=utf-8'); // utf-8인코딩
function strChk($string){
$t_string = str_replace("'", "\'", $string);
//$t_string = str_replace("/", "###", $t_string);
//$t_string = str_replace(";", ":", $t_string);
return $t_string;
}
function strRoll($string){
//$t_string = str_replace("###", "'", $string);
$t_string = $string;
return $t_string;
}
?>