PHP 프로그래밍

본문 바로가기
사이트 내 전체검색


Web Programming >> PHP Programming
[목차]
제12장 게시판 프로그램(MySQL)

    1. MySQL을 이용한 게시판 만들기

 

1. 게시판 테이블 만들기

    create table board (
    uid       int not null default '0' auto_increment,
    num    int  not null default '0',
    writer   varchar(20),
    email   varchar(60),
    subject    varchar(50),
    content    blob,
    passwd    varchar(30),
    r_step      varchar(250),
    regtime    datetime,
    visit         int,
    primary key(uid));

 

 

2. 게시판의 기능들...

  • 게시물 목록 출력(list.html)
  • 새로운 게시물 등록하기(writeform.html, write.html)
  • 게시물 내용보기(read.html)
  • 게시물 답변글 쓰기(replyform.html, reply.html)
  • 게시물 수정하기(modifyform.html, modify.html)
  • 게시물 삭제하기(deleteform.html, delete.html)

 

<그림> 게시판 흐름도

 

 

3. 목록출력하기(list.html)

 

<?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

if(!$db)

{

        echo "<SCRIPT>alert('게시판 DB Name이 입력되지 않았습니다.');history.go(-1);</SCRIPT>";

        exit;

}

 

$query = "SELECT count(*) FROM $db";

$result = mysql_query($query,$connect);

$row = mysql_fetch_row($result);

$total = $row[0];

 

if(!$page) $page=1;

$ppage = $page - 1;

$npage = $page + 1;

$pgsize = 10;

$totalpage = (int)($total/$pgsize);

if(($total%$pgsize) <> 0) $totalpage++;

$rcount=1;

 

        echo "

<HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

</HEAD>

<BODY BGCOLOR=eeeeee>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 게시판 ]</FONT><BR>

 

<TABLE BORDER=0 WIDTH=600 CELLSPACING=1>

<FORM NAME=PAGE>

<TR>

        <TD ALIGN=LEFT><FONT SIZE=2>총 게시물 : $total</TD>

        <TD ALIGN=RIGHT><FONT SIZE=2>현재 페이지 :

        <SELECT NAME=PAGE onchange=\"location.replace('list.html?db=$db&page='+document.PAGE.PAGE.value);\">";

for($i=1;$i<=$totalpage;$i++)

{

        if($i==$page) echo "<OPTION VALUE='$i' SELECTED>$i / $totalpage</OPTION>";

        else echo "<OPTION VALUE='$i'>$i / $totalpage</OPTION>";

}

        echo "</SELECT></TD>

</TR>

</FORM>

</TABLE>

<TABLE BORDER=0 WIDTH=600 CELLSPACING=1 BGCOLOR='black'>

<TR>

        <TD ALIGN=CENTER BGCOLOR=bbbbbb WIDTH=30><FONT SIZE=2 COLOR=black>번호</TD>

        <TD ALIGN=CENTER BGCOLOR=bbbbbb WIDTH=350><FONT SIZE=2 COLOR=black>제목</TD>

        <TD ALIGN=CENTER BGCOLOR=bbbbbb WIDTH=110><FONT SIZE=2 COLOR=black>작성자</TD>

        <TD ALIGN=CENTER BGCOLOR=bbbbbb WIDTH=30><FONT SIZE=2 COLOR=black>조회</TD>

        <TD ALIGN=CENTER BGCOLOR=bbbbbb WIDTH=80><FONT SIZE=2 COLOR=black>작성시간</TD>

</TR>";

$query = "SELECT num,subject,writer,visit,regtime,r_step FROM $db ORDER BY num DESC,r_step ASC";

$result = mysql_query($query,$connect);

for($i=1;$i<=$pgsize*($page-1);$i++) $row=mysql_fetch_array($result);

 

while($row = mysql_fetch_array($result))

{

        $writer = stripslashes($row[writer]);

        $email = stripslashes($row[email]);

        $subject = stripslashes($row[subject]);

        $content = stripslashes($row[content]);

        $passwd = stripslashes($row[passwd]);

 

        $regtime = substr($row[regtime],0,10);

        echo "

<TR>

        <TD ALIGN=CENTER BGCOLOR='eeeeee'><FONT SIZE=2>";

        if($row[r_step] == 0) echo $row[num];

        else echo "&nbsp;";

        echo "</FONT></TD>

        <TD BGCOLOR='eeeeee'><FONT SIZE=2>";

        if($row[r_step] != 0) echo "&nbsp;&nbsp;&nbsp;&nbsp;☞&nbsp;";

        echo "&nbsp;<A HREF='read.html?db=$db&num=$row[num]&page=$page&r_step=$row[r_step]'>$subject</A></FONT></TD>

        <TD ALIGN=CENTER BGCOLOR='eeeeee'><FONT SIZE=2>$writer</FONT></TD>

        <TD ALIGN=CENTER BGCOLOR='eeeeee'><FONT SIZE=2>$row[visit]</FONT></TD>

        <TD ALIGN=CENTER BGCOLOR='eeeeee'><FONT SIZE=2>$regtime</FONT></TD>

</TR>";

        if($rcount == $pgsize) break;

        else $rcount++;

}

echo "

</TABLE><BR>

<TABLE WIDTH=600 CELLSPACING=1 CELLPADDING=3>

<TR>

        <TD ALIGN=LEFT><FONT SIZE=2>

        [ ";

        if($page > 1) echo "<A HREF='list.html?db=$db&page=$ppage'>이전페이지</A>";

        else echo "이전페이지";

        echo "]&nbsp;&nbsp;

        [ <A HREF='writeform.html?db=$db&page=$page'>글쓰기</A> ]&nbsp;&nbsp;

        [ ";

        if($page < $totalpage) echo "<A HREF='list.html?db=$db&page=$npage'>다음페이지</A>";

        else echo "다음페이지";

        echo "]</TD>

        <TD ALIGN=RIGHT></TD>

        </FORM>

</TR>

</TABLE>";

 

?>

 

 

4. 새로운 게시물 등록하기(writeform.html, write.html)

 

등록 폼 만들기(writeform.html)

<HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

 

<SCRIPT LANGUAGE='javascript'>

function chk_form()

{

        if(document.signform.writer.value == '') alert('이름을 입력하여 주세요.');

        else if(document.signform.subject.value == '') alert('제목을 입력하여 주세요');

        else if(document.signform.content.value.length < 10) alert('내용을 성심껏 입력해주세요');

        else if(document.signform.passwd.value == '') alert('비밀번호는 추후 글을 수정,삭제하는데 필요하니 입력해주세요.');

        else document.signform.submit();

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR='eeeeee'>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 게시판 ]</FONT><BR>

<FORM NAME='signform' METHOD=POST ACTION='write.html'>

<TABLE WIDTH=600 BGCOLOR=black CELLSPACING=1>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 쓴 이</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='writer' SIZE=12 MAXLENGTH=12></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>E-Mail</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='email' SIZE=50 MAXLENGTH=100></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 제 목</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='subject' SIZE=50 MAXLENGTH=100></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 내 용</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><TEXTAREA NAME='content' ROWS=10 COLS=67></TEXTAREA></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>비밀번호</TD>

        <TD BGCOLOR='eeeeee'><INPUT TYPE=PASSWORD NAME='passwd' SIZE=12 MAXLENGTH=12>

</TR>

</TABLE>

<TABLE WIDTH=600 BGCOLOR=eeeeee>

<TR>

        <TD ALIGN=CENTER>

        <INPUT TYPE='BUTTON' VALUE='저장' onclick='chk_form();'>&nbsp;&nbsp;

        <INPUT TYPE='BUTTON' VALUE='취소' onclick='javascript:location = "<?echo("list.html?db=$db&page=$page");?>"'></TD>

</TR>

</TABLE>

<INPUT TYPE=HIDDEN NAME=db VALUE='<?echo $db;?>'>

</FORM>

</BODY>

</HTML>

 

등록 처리 프로그램(write.html)

<?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$writer = addslashes($writer);

$email = addslashes($email);

$subject = addslashes($subject);

$content = addslashes($content);

$passwd = addslashes($passwd);

 

$query = "SELECT max(num) FROM $db";

$result = mysql_query($query,$connect);

$num = mysql_result($result,0,0)+1;

 

$query = "INSERT INTO $db (num,writer,email,subject,content,passwd,r_step,regtime,visit) VALUES ($num,'$writer','$email','$subject','$content','$passwd','0',NOW(),0)";

$result = mysql_query($query,$connect);

echo "<SCRIPT>location.replace('list.html?db=$db&page=$page');</SCRIPT>";

?>

 

 

5. 게시물 내용 보기(read.html)

 

<?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$query = "UPDATE $db SET visit=visit+1 WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$query = "SELECT * FROM $db WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

 

$writer = stripslashes($row[writer]);

$email = stripslashes($row[email]);

$subject = stripslashes($row[subject]);

$content = stripslashes($row[content]);

$passwd = stripslashes($row[passwd]);

 

$content = nl2br($content);

echo "

<HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

 

</HEAD>

<BODY BGCOLOR=eeeeee LINK=black ALINK=black VLINK=black>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 게시판 ]</FONT><BR>

 

<TABLE WIDTH=600 CELLSPACING=1 CELLPADDING=3 BGCOLOR=black>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=80><FONT SIZE=2 COLOR=black>작성자</FONT></TD>

        <TD BGCOLOR='eeeeee' WIDTH=280><FONT SIZE=2>&nbsp;$writer</TD>

        <TD BGCOLOR='bbbbbb'

        ALIGN=CENTER WIDTH=80><FONT SIZE=2 COLOR=black>작성시간</FONT></TD>

        <TD BGCOLOR='eeeeee' WIDTH=160 ALIGN=CENTER><FONT SIZE=2>$row[regtime]</TD>

</TR>

<TR>

 

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=80><FONT SIZE=2 COLOR=black>E-Mail</FONT></TD>

        <TD BGCOLOR='eeeeee' WIDTH=280>

        <FONT SIZE=2><A HREF='mailto:$row[email]'>$row[email]</A></TD>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=80><FONT SIZE=2 COLOR=black>조회수</FONT></TD>

        <TD BGCOLOR='eeeeee' WIDTH=160 ALIGN=CENTER><FONT SIZE=2>$row[visit]</TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=bbbbbb COLSPAN=1>

          <FONT SIZE=2 COLOR=black>제목</FONT></TD>

        <TD BGCOLOR='eeeeee' COLSPAN=3><FONT SIZE=2>&nbsp;$subject</TD>

</TR>

</TABLE>

<BR>

<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 BGCOLOR='black' WIDTH=600>

<TR>

        <TD BGCOLOR='eeeeee' COLSPAN=2><BR><FONT SIZE=2>$content<BR><BR></TD>

</TR>

</TABLE>

<BR>

<TABLE WIDTH=600 CELLSPACING=1 CELLPADDING=3>

<TR>

        <TD ALIGN=CENTER><FONT SIZE=2>

        [ <A HREF='list.html?db=$db&page=$page'>글목록</A> ]&nbsp;&nbsp;

        [ <A HREF='modifyform.html?db=$db&num=$num&r_step=$r_step&page=$page'>글수정</A> ]&nbsp;&nbsp;

        [ <A HREF='replyform.html?db=$db&num=$num&r_step=$r_step&page=$page'>답변글</A> ]&nbsp;&nbsp;

        [ <A HREF='deleteform.html?db=$db&num=$num&r_step=$r_step&page=$page'>삭제하기</A> ]</TD>

</TR>

</TABLE>";

?>

 

6. 답변글 쓰기(replyform.html, reply.html)

 

 

답변글 쓰기 폼 만들기(replyform.html)

 <?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$query = "SELECT content FROM $db WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

 

$writer = stripslashes($row[writer]);

$email = stripslashes($row[email]);

$subject = stripslashes($row[subject]);

$content = stripslashes($row[content]);

$passwd = stripslashes($row[passwd]);

 

?>

<HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

 

<SCRIPT LANGUAGE='javascript'>

function chk_form()

{

        if(document.replyform.writer.value == '') alert('이름을 입력하여 주세요.');

        else if(document.replyform.subject.value == '') alert('제목을 입력하여 주세요');

        else if(document.replyform.content.value.length < 10) alert('내용을 성심껏 입력해주세요');

        else if(document.replyform.passwd.value == '') alert('비밀번호는 추후 글을 수정,삭제하는데 필요하니 입력해주세요.');

        else document.replyform.submit();

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR='eeeeee'>

<CENTER>

<FORM NAME='replyform' METHOD=POST ACTION='reply.html'>

<TABLE WIDTH=600 BGCOLOR=black CELLSPACING=1>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 쓴 이</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='writer' SIZE=12 MAXLENGTH=12></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>E-Mail</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='email' SIZE=50 MAXLENGTH=100></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 제 목</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='subject' SIZE=50 MAXLENGTH=100 VALUE='☞ <?echo "$row[subject]";?>'></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 내 용</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><TEXTAREA NAME='content' ROWS=10 COLS=67>

        <?echo "답변 : $row[content]

------------------------------------------------------------\n";?>

        </TEXTAREA></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>비밀번호</TD>

        <TD BGCOLOR='eeeeee'><INPUT TYPE=PASSWORD NAME='passwd' SIZE=12 MAXLENGTH=12>

</TR>

</TABLE>

<TABLE WIDTH=600 BGCOLOR=eeeeee>

<TR>

        <TD ALIGN=CENTER>

        <INPUT TYPE='BUTTON' VALUE='저장' onclick='chk_form();'>&nbsp;&nbsp;

        <INPUT TYPE='BUTTON' VALUE='취소' onclick='javascript:location = "<?echo("list.html?db=$db&page=$page");?>"'></TD>

</TR>

</TABLE>

<INPUT TYPE=HIDDEN NAME=db VALUE='<?echo $db;?>'>

<INPUT TYPE=HIDDEN NAME=num VALUE='<?echo $num;?>'>

<INPUT TYPE=HIDDEN NAME=page VALUE='<?echo $page;?>'>

</FORM>

</BODY>

</HTML>

 

 

답변글 쓰기 처리 프로그램(reply.html)

 <?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$writer = addslashes($writer);

$email = addslashes($email);

$subject = addslashes($subject);

$content = addslashes($content);

$passwd = addslashes($passwd);

 

 

$query = "SELECT r_step FROM $db WHERE num=$num ORDER BY r_step DESC";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

$r_step = $row[r_step] + 1;

 

$query = "INSERT INTO $db (num,writer,email,subject,content,passwd,r_step,regtime,visit) VALUES ($num,'$writer',  '$email','$subject','$content','$passwd','$r_step',NOW(),0)";

$result = mysql_query($query,$connect);

if(!$result) {

        echo($query);

        exit;

}

echo "<SCRIPT>location.replace('list.html?db=$db&page=$page');</SCRIPT>";

 

?>

 

 

 

7. 게시물 수정하기(modifyform.html, modify.html)

 

게시물 수정 폼 만들기(modifyform.html)

 <?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

if(!$r_step) $r_step=0;

$query = "SELECT * FROM $db WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

 

$writer = stripslashes($row[writer]);

$email = stripslashes($row[email]);

$subject = stripslashes($row[subject]);

$content = stripslashes($row[content]);

$passwd = stripslashes($row[passwd]);

 

?>

<HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

<SCRIPT LANGUAGE='javascript'>

function chk_form()

{

        if(document.modifyform.writer.value == '') alert('이름을 입력하여 주세요.');

        else if(document.modifyform.subject.value == '') alert('제목을 입력하여 주세요');

        else if(document.modifyform.content.value.length < 10) alert('내용을 성심껏 입력해주세요');

        else if(document.modifyform.passwd.value == '') alert('글을 수정하시려면 비밀번호가 필요합니다..');

        else document.modifyform.submit();

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR='eeeeee'>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 게시판 ]</FONT><BR>

 

<FORM NAME='modifyform' METHOD=POST ACTION='modify.html'>

<TABLE WIDTH=600 BGCOLOR=black CELLSPACING=1>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 쓴 이</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='writer' SIZE=12 MAXLENGTH=12 VALUE='<?echo $writer;?>'></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>E-Mail</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='email' SIZE=50 MAXLENGTH=100 VALUE='<?echo $email;?>'></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 제 목</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><INPUT TYPE=TEXT NAME='subject' SIZE=50 MAXLENGTH=100 VALUE='<?echo $subject;?>'></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>글 내 용</TD>

        <TD BGCOLOR='eeeeee' WIDTH=500><TEXTAREA NAME='content' ROWS=10 COLS=67><?echo $content;?></TEXTAREA></TD>

</TR>

<TR>

        <TD BGCOLOR='bbbbbb' ALIGN=CENTER WIDTH=100><FONT SIZE=2 COLOR='black'>비밀번호</TD>

        <TD BGCOLOR='eeeeee'><INPUT TYPE=PASSWORD NAME='passwd' SIZE=12 MAXLENGTH=12>

</TR>

</TABLE>

<TABLE WIDTH=600 BGCOLOR=eeeeee>

<TR>

        <TD ALIGN=CENTER>

        <INPUT TYPE='BUTTON' VALUE='저장' onclick='chk_form();'>&nbsp;&nbsp;

        <INPUT TYPE='BUTTON' VALUE='취소' onclick='javascript:location = "<?echo("list.html?db=$db&page=$page");?>"'></TD>

</TR>

</TABLE>

<INPUT TYPE=HIDDEN NAME=db VALUE='<?echo $db;?>'>

<INPUT TYPE=HIDDEN NAME=num VALUE='<?echo $num;?>'>

<INPUT TYPE=HIDDEN NAME=r_step VALUE='<?echo $r_step;?>'>

<INPUT TYPE=HIDDEN NAME=page VALUE='<?echo $page;?>'>

 

</FORM>

</BODY>

</HTML>

 

 

게시물 수정 처리 프로그램(modify.html)

 <?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$writer = addslashes($writer);

$email = addslashes($email);

$subject = addslashes($subject);

$content = addslashes($content);

$passwd = addslashes($passwd);

 

$query = "SELECT passwd FROM $db WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

 

if($row[passwd] == $passwd) {

        $query = "UPDATE $db SET writer='$writer',email='$email',subject='$subject',content='$content' WHERE num=$num AND r_step='$r_step'";

        $result = mysql_query($query,$connect);

        echo "<SCRIPT>location.replace('read.html?db=$db&num=$num&r_step=$r_step&page=$page');</SCRIPT>";

}

else {

        echo "<SCRIPT>alert('비밀번호가 틀렸습니다.');history.go(-1);</SCRIPT>";

        exit;

}

?>

 

 

8. 게시물 삭제하기(deleteform.html, delete.html)

 

게시물 삭제 폼 만들기(deleteform.html)

 <HEAD>

<TITLE>LeeLAB - 게시판</TITLE>

<STYLE TYPE='text/css'>

<!--

A:link{text-decoration:none;color:}

A:visited{text-decoration:none;color:}

A:hover {background-color:dddddd}

-->

</STYLE>

</HEAD>

<BODY>

<CENTER>

<FONT SIZE=6 FACE='Comic Sans MS'>[ 게시판 ]</FONT><BR>

 

<FORM METHOD=POST ACTION=delete.html>

<TABLE WIDTH=300 CELLSPACING=1 CELLPADDING=3 BGCOLOR=black>

<TR>

        <TD ALIGN=CENTER BGCOLOR=dddddd><FONT SIZE=2>게시물 암호</FONT></TD>

</TR>

<TR>

        <TD ALIGN=CENTER BGCOLOR=dddddd><INPUT TYPE=PASSWORD NAME=passwd SIZE=10></TD>

</TR>

<TR>

        <TD ALIGN=CENTER BGCOLOR=dddddd><INPUT TYPE=SUBMIT VALUE='삭제하기'>

        <INPUT TYPE='BUTTON' VALUE='취소' onclick='javascript:location = "<?echo("list.html?db=$db&page=$page");?>"'></TD>

</TR>

</TABLE>

<INPUT TYPE=HIDDEN NAME=db VALUE='<?echo $db;?>'>

<INPUT TYPE=HIDDEN NAME=num VALUE='<?echo $num;?>'>

<INPUT TYPE=HIDDEN NAME=r_step VALUE='<?echo $r_step;?>'>

<INPUT TYPE=HIDDEN NAME=page VALUE='<?echo $page;?>'>

</FORM>

</BODY>

</HTML>

 

 

 

게시물 삭제 처리 프로그램(delete.html)

<?

$connect = mysql_connect("localhost","php","php99");

mysql_select_db("sample",$connect);

 

$writer = addslashes($writer);

$email = addslashes($email);

$subject = addslashes($subject);

$content = addslashes($content);

$passwd = addslashes($passwd);

 

$query = "SELECT passwd FROM $db WHERE num=$num AND r_step='$r_step'";

$result = mysql_query($query,$connect);

$row = mysql_fetch_array($result);

 

if($row[passwd] == $passwd) {

        $query = "DELETE FROM $db WHERE num=$num AND r_step='$r_step'";

        $result = mysql_query($query,$connect);

        echo "<SCRIPT>location.replace('list.html?db=$db&page=$page');</SCRIPT>";

}

else {

        echo "<SCRIPT>alert('비밀번호가 틀렸습니다.');history.go(-1);</SCRIPT>";

        exit;

}

?>

 

[목차]

개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.