소소한 IT이야기/PHP_개발

[M2 MAMP] PHP 게시판 구축 - 05 (feat.수정(U)/삭제(D))

Klaus 2023. 8. 12. 16:21

 

 

1. 게시글 수정 기능(update.php)

글 수정 화면 페이지를 만들어 줍니다.(update.php)read.php와 비슷하게 하게 작성되지만,

다른점은 조회수 부분과 연결되는  <form action=update_ok.php로 변경된 점이 다릅니다.

<?php
	include "./config.php";
	include "./db/db_con.php";
	include "./login_check.php";
	
	$bno = $_GET['idx'];
	$sql = mq("select  * from  board where idx='$bno'");
	$board = $sql->fetch_array();	
?>
<!DOCTYPE html>
<html>

	<body>
		<nav class="navbar navbar-default">
			<?php include_once "./fragments/header.php";?>
		</nav>
		<div class="container">
			<div id="board_write">
                <form action="update_ok.php/<?php echo $board['idx']; ?>" method="post">
                <input type="hidden" name="idx" value="<?=$bno?>" />
					<table class="table table-striped" style="text-align: center; border: 1px solid #ddddda">
						<thead>
							<tr>
								<th colspan="2" style="background-color: #eeeeee; text-align: center;"><h3>게시판 수정</h3></th>
							</tr>
						</thead>	
						<tbody>
							<tr>
								<td><span class="pull-left">&nbsp;&nbsp;&nbsp;아이디 : <b><?=$userid?></b></span></td>
							</tr>
							<tr>
								<td><input type="text" class="form-control" placeholder="제목" name="title" id="utitle" value="<?=$board['title']?>" required></td>
							</tr>
							<tr>
								<td><input type="password" class="form-control" placeholder="비밀번호" name="pw" id="upw" style="width: 150px;"></td>
							</tr>
							<tr>	
								<td><textarea class="form-control" placeholder="내용" name="content" id="ucontent" style="height: 350px" required><?=$board['content']?></textarea></td>
							</tr>
						</tbody>
					</table>
					<button type="submit" class="btn btn-primary">글쓰기</button>
				</form>
			</div>
		</div>
		<script src="./js/login.js"></script>       
	</body>
</html>

 

2. 게시글 삭제 기능(delete.php)

<?php
	include "./db/db_con.php";
	$bno = $_GET['idx'];
	mq("delete from board where idx='$bno'");
?>
	<script>
		alert("삭제되었습니다.");
	</script>
	<meta http-equiv="refresh" content="0 url=/board/list.php">