리스트.
<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&page=<?=$page?>&num=<?=$cnum?>&com=edit&dnul=<?=$array[0]?>'>
수정</a>
<a href='<?=$PHP_SELF?>?case=view&page=<?=$page?>&num=<?=$cnum?>&com=del&dnul=<?=$array[0]?>'>
삭제</a>
<? }else{
echo " ";
}
}else{
echo " ";
}?>
</div>
<? } //댓글 리스트 ?>
<? if($sessionid != null){ //작성 폼 세션 값이 있을때?>
<form name="view_comment" method="post" onsubmit="return check2();"
action="<?=$PHP_SELF?>?case=view&page=<?=$page?>&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 " ";
}
} //여기까지?>
쓰기
<?
$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&page=$page&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();
?>
'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 |