테이블
CREATE TABLE `comment_tbl` (
`num` INT(11) NOT NULL AUTO_INCREMENT,
`cnum` INT(11) NULL DEFAULT NULL,
`did` INT(11) NULL DEFAULT NULL,
`name` VARCHAR(30) NULL DEFAULT NULL,
`indate` DATETIME NULL DEFAULT NULL,
`ip` VARCHAR(15) NULL DEFAULT NULL,
`passwd` VARCHAR(50) NULL DEFAULT NULL,
`detail` TEXT NULL,
PRIMARY KEY (`num`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM


리스트.

<script type="text/javascript">

function check2(){ //작성시

var comment = document.view_comment;

if(comment.detail2.value==""){

alert('내용을 입력해주세요');

comment.detail2.focus();

return false;

}

 

  if(comment.passwd.value==""){

alert('수정,삭제 처리를 위해 비밀번호를 입력해주세요');

comment.passwd.focus();

return false;

}

}


function check3(){ //수정

var comment = document.com_update;

if(comment.detail2.value==""){

alert('내용을 입력해주세요');

comment.detail2.focus();

return false;

}

if(comment.passwd.value==""){

alert('비밀번호를 입력해주세요');

comment.passwd.focus();

return false;

}

}


function check4(){ //삭제

var comment = document.com_delete;

if(comment.passwd.value==""){

alert('비밀번호를 입력해주세요');

comment.passwd.focus();

return false;

}

}

</script>


<? //추가부분

$sessionid = $_SESSION['sessionid']; //세션아이디

//$sessionid = "아직";

$cnum = $array['num']; //게시물 번호


$query = "select * from comment_tbl where cnum=$cnum order by indate";

$result = mysql_query($query) or die (mysql_error());


if($com == 'edit'){ //수정

include "../board/comment/comment_update.php";

}if($com == 'del'){ //삭제

include "../board/comment/comment_delete.php";

}if($com == 'write'){ //작성

include "../board/comment/comment_write.php";

}else{

// 댓글 리스트

for($i=0; $i<$array = mysql_fetch_array($result); $i++){

$detail=stripslashes($array[7]);

$detail=nl2br($detail); //엔터를 <br>로 바꾸기

?>


<div >

<table class="list_read1" summary="">

<caption></caption>

<colgroup><col /></colgroup>

<tr>

<td scope="row" class="tit">작성자 : <?=$array[3]?></td>

<td scope="row" class="tit">날짜 : <?=$array[4]?></td>

<td scope="row">ip : <?=$array[5]?></td>

</tr>


<tr>

<td colspan="3" class="readcon"><?=$detail?></td>

</tr>

</table>

</div>


<div class="r" style="margin-top:-30px; margin-bottom:10px;">

<? if($sessionid != null){ //세션 값이 없을때

if($array[3] == $sessionid){ //세션값과id값이 동일할때?>

<a href='<?=$PHP_SELF?>?case=view&amp;page=<?=$page?>&amp;num=<?=$cnum?>&com=edit&dnul=<?=$array[0]?>'>

수정</a>

<a href='<?=$PHP_SELF?>?case=view&amp;page=<?=$page?>&amp;num=<?=$cnum?>&com=del&dnul=<?=$array[0]?>'>

삭제</a>


<? }else{

echo "&nbsp; ";

}

}else{

echo "&nbsp; ";

}?>

</div>


<? } //댓글 리스트 ?>

<? if($sessionid != null){ //작성 폼 세션 값이 있을때?>


<form name="view_comment" method="post" onsubmit="return check2();"

action="<?=$PHP_SELF?>?case=view&amp;page=<?=$page?>&amp;num=<?=$cnum?>&com=write&wnul=<?=$array[0]?>">

<table class="type2 wps_100 mg_b20" summary="">

<caption></caption>

<colgroup><col class="w_100" /><col /></colgroup>

<tr>

<th scope="row">내용</th>

<td><textarea class="w_500" rows="3" cols="100" name="detail2"></textarea>

</td></tr>

<tr>

<th scope="row">비밀번호</th>

<td><input type="password" class="w_200" name="passwd" id="pwd">

</td></tr>

</table>

<div class="r" style="margin-top:-20px; margin-bottom: 20px;">

<input type="submit" value="작 성" class="no_border">

</div>

</form>


<?}else {

echo "&nbsp; ";

}

} //여기까지?>



쓰기


<?


$name = $_SESSION['sessionid']; //아이디

$indate = date("Y-m-d H:i:s");//날짜

$ip = $REMOTE_ADDR; //ip



echo

"<script type='text/javascript'>

alert('작성완료');

location.href='$PHP_SELF?case=view&amp;page=$page&amp;num=$cnum';

</script>";

$query = "insert into comment_tbl (cnum, did, name, indate, ip, passwd, detail)

values($cnum, $data_id, '$name', '$indate', '$ip', '$passwd', '$detail2')";

mysql_query($query)  or die (mysql_error());


mysql_close();

?>



수정
<?
$query = "select * from comment_tbl where num=$dnul"; //해당 컬럼 번호로불러오기
$result = mysql_query($query);


if($com_update_ == 'update'){ //폼 값이 있을때
if($passwd == $passwd2){ // 비번이 동일할경우
$query = "update comment_tbl set detail='$detail2' where num=$dnul && passwd='$passwd'";
$result = mysql_query($query);
mysql_close();
echo
"<script type='text/javascript'>
alert('수정완료');
location.href='$PHP_SELF?case=view&amp;page=$page&amp;num=$cnum';
</script>";
}else{ // 틀릴경우
echo
"<script type='text/javascript'>
alert('수정실패');
location.href='$PHP_SELF?case=view&amp;page=$page&amp;num=$cnum';
</script>";
}
}else{ // 폼 값이 없을때
?>
<div style="margin-bottom: 10px;">
<form name="com_update" method="post" onsubmit="return check3();" 
action="<?=$PHP_SELF?>?case=view&amp;page=<?=$page?>&amp;num=<?=$cnum?>&com=edit&dnul=<?=$dnul?>">
<? while ($array = mysql_fetch_array($result)){
$detail=stripslashes($array[7]);
//$detail=nl2br($detail); //엔터를 <br>로 바꾸기?>
<table class="list_read1" summary="">
<caption></caption>
<colgroup><col class="w_100" /><col /></colgroup>
<tr><th scope="row">내용</th>
<td><textarea class="w_500" rows="3" cols="100" name="detail2"><?=$detail?></textarea>
</td></tr>
<tr>
<th scope="row">비밀번호</th>
<td><input type="password" class="w_200" name="passwd" id="pwd">
<input type="submit" value="수정">
</td></tr>
    </table>
    <input type="hidden" name="passwd2" value=<?=$array[6]?>>
    <input type="hidden" name="com_update_" value="update">
<? }?>
</form>
</div>
<? }?>

삭제
<?
$query = "select * from comment_tbl where num=$dnul";
$result = mysql_query($query);

if($com_delete_ == "delete"){ // 폼 값이 있을때
if($passwd == $passwd2){ // 비번이 동일할때
$query = "delete from comment_tbl where num= $dnul && passwd= '$passwd' ";
$result = mysql_query($query);
mysql_close();
echo "<script type='text/javascript'>
alert('삭제완료');
location.href='$PHP_SELF?case=view&amp;page=$page&amp;num=$cnum';
</script>";
}else{ // 비번이 틀릴떄
echo
"<script type='text/javascript'>
alert('삭제실패');
location.href='$PHP_SELF?case=view&amp;page=$page&amp;num=$cnum';
</script>";
}

}else{ // 폼 값이 없을때
?>
<div style="margin-bottom: 10px;">
<form name="com_delete" method="post" onsubmit="return check4();" 
action="<?=$PHP_SELF?>?case=view&amp;page=<?=$page?>&amp;num=<?=$cnum?>&com=del&dnul=<?=$dnul?>">
<? while ($array3 = mysql_fetch_array($result)){?>
<table class="list_read1" summary="">
<caption></caption>
<colgroup><col class="w_100" /><col /></colgroup>
<tr>
<th scope="row">비밀번호</th>
<td><input type="password" class="w_200" name="passwd" id="pwd">
<input type="submit" value="삭제">
</td>
</tr>
</table>
 <input type="hidden" name="passwd2" value=<?=$array3[6]?>>
 <input type="hidden" name="com_delete_" value="delete">
<? }?>
</form>
</div>
<? }?>


 현재 소스는 게시판소스가 있는 가정에서 만든것입니다. 아직 많이 미흡합니다^^.







'progarm_old > [PHP]' 카테고리의 다른 글

[php] 역슬러쉬제거,생성,stripslashes,addslashes  (0) 2012.07.12
[php] 쿼리 연결 및 출력, 넘기기  (0) 2012.07.12
엔터, 그대로 출력(줄바꿈)  (0) 2012.06.15
php 보안 30가지  (0) 2012.06.08
문자열 제어하기  (0) 2012.06.08

+ Recent posts