윗글, 아랫글 클릭시 오류

윗글, 아랫글 클릭시 오류

QA

윗글, 아랫글 클릭시 오류

본문

1ab26149faf7037327a9ce5e2393320b_1435801408_0726.png 

 

게시판 목록에서 바로 클릭하면 오류는 안나는데 스크린샷같이 저기서 위로,아래로 클릭해서 게시물을 변경하면 오류가 나옵니다 어디가 잘못된건가요??
주소 나오는데 보면 no값이 안들어오는것 같은데 원래 없는건가요??  

 

사진과 같은 read.php

 

<?php
</html>
include "db_info.php";
$id=$_GET['id']; $no=$_GET['no'];

//조회수 업데이트
$query="update aa_common_$board set view=view+1 where id=$id";
$result=mysql_query($query,$conn);

//글 정보 가져오기
$query="select * from $board where id=$id";
$result=mysql_query($query,$conn);
$row=mysql_fetch_array($result);
?>
<html>
<head>
<title>계층형 게시판</title>
<style>
<!--
td{font-size:9pt;}
A:link[font:9pt; color:black; text_decoration:none;
font-family:굴림; font-size:none; color:black;
A:visited{text-decoration:none; color:black;
font-size:9pt;}
A:hover{text-decoration:underline; color:black;
font-size:9pt;}
-->
</style>
</head>
<body topmargin=0 leftmargin=0 text=#464646>
<center>
<br>
<table width=580 border=0 cellpadding=2 cellspacing=1 bgcolor=#777777>
<tr>
 <td height=20 colspan=4 align=center bgcolor=#999999>
  <font color=white><b><?=strip_tags($row['title']);?>
  </b></font>
 </td>
</tr>
<tr>
 <td width=50 height=20 align=center bgcolor=#EEEEEE>글쓴이</td>
 <td width=240 bgcolor=white><?=$row['name']?></td>
 <td width=50 height=20 align=center bgcolor=#EEEEEE>이메일</td>
 <td width=240 bgcolor=white><?=$row['email']?></td>
</tr>
<tr>
<?php
date_default_timezone_set('Asia/Seoul');
 ?>
 <td width=50 height=20 align=center bgcolor=#EEEEEE>
  날   짜</td><td width=240 bgcolor=white>
  <?=date("Y-m-d", $row['wdate'])?></td>
 <td width=50 height=20 align=center bgcolor=#EEEEEE>조회수</td>
 <td width=240 bgcolor=white><?=$row['view']?></td>
</tr>
<tr>
 <td bgcolor=white colspan=4 style="word-break:break-all;">
  <font color=black>
  <pre><?=strip_tags($row['content']);?></pre>
  </font>
 </td>
</tr>
<!-- 기타 버튼 들 -->
<tr>
 <td colspan=4 bgcolor=#999999>
 <table width=100%>
 <tr>
  <td width=280 align=left height=20>
   <a href=list.php?no=<?=$no?>><font color=white>
   [목록보기]</font></a>
   <a href=list.php?id=<?=$id?>><font color=white>
   [답글달기]</font></a>
   <a href=write.php><font color=white>
   [글쓰기]</font></a>
   <a href=list.php?id=<?=$id?>><font color=white>
   [수정]</font></a>
   <a href=predel.php?id=<?=$id?>><font color=white>
   [삭제]</font></a>
  </td>
 </tr>
 </table>
 </td>
</tr>
</table>

<table width=580 bgcolor=white style="border-bottom-width:1;
border-bottom-style:solid;border-bottom-color:cccccc;">
<?
//현재 글보다 thread 값이 큰 글 중 가장 작은 것의 id를 가져온다
$query = "select id, name, title from $board
where thread>$row[thread] order by thread asc limit 1";
$result=mysql_query($query,$conn);
$up_id=mysql_fetch_array($result);

if($up_id['id']) //이전 글이 있을 경우
{
 echo "<tr><td width=500 align=left height=25>";
 echo "<a href=read.php?id=$up_id[id]>위로 $up_id[title]</a></td>
 <td align=right>$up_id[name]</td></tr>"; 
}
//현재 글보다 thread 값이 작은 글 중 가장 큰 것의 id를 가져온다
$query = "select id, name, title from $board where
thread<$row[thread] order by thread desc limit 1";
$result=mysql_query($query,$conn);
$down_id=mysql_fetch_array($result);

if($down_id['id'])
{
 echo "<tr><td width=500 align=left height=25>";
 echo "<a href=read.php?id=$down_id[id]>아래 $down_id[title]</a></td>
 <td align=right>$down_id[name]</td></tr>";
}
?>
</table>
<br>
<?
/*리스트 출력을 위해 thread를 계산한다
출력될 리스트는 글 전체 리스트가 아니라
1000의 배수인 새 글과 이를 포함한 답변 글들의 리스트이다
답변 글이 없는 경우 원본 글만 리스트에 나오고
답변 글이 있으면 답변 글 모두가 다 나오게 된다
현재 글이 답변 글이어도 새 글부터 전체 답변 글까지 나온다
그렇다면 1000-2000과 같이 새 글 사이에 글들을 모두 뿌려주면 된다 */

$thread_end=ceil($row['thread']/1000)*1000;
$thread_start=$thread_end-1000;

$query="select*from $board where thread <= $thread_end and
thread>$thread_start order by thread desc";
$result=mysql_query($query,$conn);
?>
<!-- 게시물 리스트를 보이기 위한 테이블 -->
<table width=580 border=0 cellpadding=2 cellspacing=1 bgcolor=#777777>
<!-- 리스트 타이블 부분 -->
<tr height=20 bgcolor=#999999>
 <td width=30 align=center>
  <font color=white>번호</font>
 </td>
 <td width=370 align=center>
  <font color=white>제목</font>
 </td>
 <td width=50 align=center>
  <font color=white>글쓴이</font>
 </td>
 <td width=60 align=center>
  <font color=white>날짜</font>
 </td>
 <td width=40 align=center>
  <font color=white>조회수</font>
 </td>
</tr>
<!-- 리스트 타이틀 끝 -->
<!-- 리스트 부분 시작 -->
<?
 while ($row=mysql_fetch_array($result))
 {
?>
<!-- 행 시작 -->
<tr>
<!-- 번호 -->
 <td height=20 bgcolor=white align=center>
  <a href="read.php?id=<?=$row[id]?>&no=<?=$no?>">
  <?=$row['id']?></a>
 </td>
 <!-- 번호 끝 -->
 <!-- 제목 -->
 <td height=20 bgcolor=white> 
  <? //depth갓을 통해서 들여쓰기를 한다 투명 이미지의 가로 사이즈를 늘이는 방법
  if($row['depth']>0)
  echo "<img src=img/dot.gif height=1 width" .
  $row[depth]*7 . ">->"; 
  ?>
  <a href="read.php?id=<?=$row[id]?>&no=<?=$no?>">
  <?=strip_tags($row['title'], '<b><i>');?></a>
 </td>
 <!-- 제목 끝 -->
 <!-- 이름 -->
 <td align=center height=20 bgcolor=white>
  <font color=black>
  <a href="<?=$row['name']?>mailto:<?=$row[email]?>"><?=$row['name']?></a>
  </font>
 </td>
 <!-- 이름 끝 -->
 <!-- 날짜 -->
 <td align=center eight=20 bgcolor=white>
  <font color=black><?=date("Y-m-d",$row['wdate'])?></font>
 </td>
 <!-- 날짜 끝 -->
 <!-- 조회수 -->
 <td align=center height=20 bgcolor=white>
  <font color=black><?=$row['view']?></font>
 </td>
 <!-- 조회수 끝 -->
</tr>
<!-- 행 끝 -->
<?
 } //end while
mysql_close($conn);
?>
</center>
</body>
</html>​

 

 

 

 


 

게시판목록 list.php
<?php
//데이터베이스 연결하기
include "db_info.php";

####################
#list 설정
#1. 한페이지에 보여질 게시물의 수
$page_size=10;

#2. 페이지 나누기에 표시될 페이지의 수
$page_list_size=10;

####################
//$no 값이 안 넘어 오거나 잘못된(음수)값이 넘어오는 경우 0으로 처리
$no=empty($_GET['no'])?1:$_GET['no'];
if($no<0) $no=1;

####################

//데이터베이스에서 페이지의 첫 번째 글($no)부터 $page_size만큼의 글을 가져온다
$query = "select*from $board order by thread desc limit $no,$page_size";
$result = mysql_query($query, $conn);

/*총 게시물 수를 구한다
count를 통해 구할 수 있는데 count(항목)과 같은 방법으로 사용한다 *는 모든 항목을 뜻한다
총 해당 항목의 값을 가지는 게시물의 개수가 얼마인가를 묻는 것이다
따라서 전체 글 수가 된다 count(id)와 같은 방법도 가능하지만
이례적으로 count(*)가 조금 빠르다 일반적으로는 *가 느리다*/
$result_count=mysql_query("select count(*) from $board",$conn);
$result_row=mysql_fetch_row($result_count);
$total_row=$result_row[0];

//결과의 첫 번째 열이 count(*)의 결과다
####################
#총 페이지 계산
if($total_row<=0) $total_row=0; //총 게시물의 값이 없을 경우 기본값으로 세팅
//총 게시물에 1을 뺀 뒤 페이지 사이즈로 나누고 소수점 이하를 버린다

$total_page = floor(($total_row-1)/$page_size);
/*총 페이지는 총 게시물의 수를 $page_size로 나누면 알 수 있다
총 게시물이 12개(1을 빼서 11이 된다)이고 페이지 사이즈가 10이라면 결과는 1.1이 나올 것이다
1.1라는 페이지 수는 한페이지를 다 표시하고도 글이 더 남아있다는 뜻이다
따라서 실제의 페이지 수는 2가 된다 한 페이지는 2개의 글만 표시될 것이다
그러나 내림을 해주는 이유는 페이지 수가 0부터 시작하기 때문이다 따라서 1은 두번째 페이지다
총 게시물에 1을 빼주는 이유는 10페이지가 되면 10/10 =1이기 때문이다
 앞에서도 말했지만 1은 2번째 페이지를 뜻한다
그러나 총 게시물이 10개인 경우 한 페이지에 모두 출력됭야 한다
그래서 1을 빼서 10개인 경우(10-1)/10=0.9로 한 페이지에 출력한다
글이 0개가 있는 경우는 결과가 -1이 되지만 -1은 무시된다
(floor는 내림을 하는 수학함수이다)*/

####################
#현재 페이지 계산
$current_page=floor($no/$page_size);
/*$no을 통해서 페이지의 첫 번째 글이 몇 번째 글인지 전달된다
따라서 페이지 사이즈로 나누면 현재가 몇 번째 페이지인지 알 수 있다
$no이 10이고 페이지 사이즈가 10이라면 결과는 1이다 앞서 페이지는 0부터
시작이라고 했으니 두 번째 페이지임을 나타낸다
그렇다면 $no이 11이라면 1.1이 되어 버린다 11번째 글도 두 번째 페이지에 존재하므로 0.1
은 무의미하니 버린다
그런데 $no이란 값이 $page_size마큼씩 증가되는 값이기 때문에(0,10,20,30과 같은
등차수열)내림을 하는 것 또한 무의미하다
그러나 내림을 하는 이유는 $no값에 11과 같은 값이 들어와도 제대로 출력되기를 바라는
마음에서 해놓은 것이다*/
?>
<html>
<head>
<title>계층형 게시판</title>
<style>
<!--
td{font-size:9pt;}
A:link{font:9pt; color:black; text-decoration:none;
font-family:굴림; font-size:9pt;}
A:visited{text-decoration:none; color:black;
font-size:9pt;}
A:hover{text-decoration:underline; color:black;
font-size:9pt;}
-->>
</style>
</head>
<body topmargin=0 leftmargin=0 text=#464646>
<center>
<br>
<!-- 게시물 리스트를 보이기 위한 테이블 -->
<table width=580 border=0 cellpadding=2 cellspacing=1 bgcolor=#777777>
<!-- 리스트 타이틀 부분 -->
<tr height=20 bgcolor=#999999>
 <td width=30 align=center>
  <font color=white>번호</font>
 </td>
 <td width=370 align=center>
  <font color=white>제목</font>
 </td>
 <td width=50 align=center>
  <font color=white>글쓴이</font>
 </td>
 <td width=60 align=center>
  <font color=white>날짜</font>
 </td>
 <td width=40 align=center>
  <font color=white>조회수</font>
 </td>
</tr>
<!-- 리스트 타이틀 끝 -->
<!-- 리스트 부분 시작 -->
<?
while($row=mysql_fetch_array($result))
{
?>
<!-- 행 시작 -->
<tr>
 <!-- 번호 -->
 <td height=20 bgcolor=white align=center>
  <a href="read.php?id=<?=$row['id']?>&no=<?=$no?>">
  <?=$row['id']?></a>
 </td>
 <!-- 번호 끝 -->
 <!-- 제목 -->
 <td height=20 bgcolor=white> 
 <?
 if($row['depth']>0)
  echo "<img height=1 width=" . $row[depth]*7 . ">L";
 ?>
 <a href="read.php?id=<?=$row['id']?>&no=<?=$no?>">
 <?=strip_tags($row['title']);?></a>
 </td>
 <!-- 제목 끝 -->
 <!-- 이름 -->
 <td align=center height=20 bgcolor=white>
  <font color=black>
  <a href="mailto:<?=$row[email]?>"><?=$row['name']?></a>
  </font>
 </td>
 <!-- 이름 끝 -->
 <!-- 날짜 -->
 <?php
date_default_timezone_set('Asia/Seoul');
 ?>
 <td align=center height=20 bgcolor=white>
  <font color=black><?=date("Y-m-d",$row['wdate'])?></font>
 </td>
 <!-- 날짜 끝 -->
 <!-- 조회수 -->
 <td align=center height=20 bgcolor=white>
  <font color=black><?=$row['view']?></font>
 </td>
 <!-- 조회수 끝 -->
</tr>
<!-- 행 끝 -->
<?
} // end while

// 데이터베이ㅣ스와의 연결을 끝는다
mysql_close($conn);
?>
</table>
<!-- 게시물 리스트를 보이기 위한 테이블 끝 -->
<!-- 페이지를 표시하기 위한 테이블 -->
<table border=0>
<tr>
 <td width=600 height=20 align=center rowspan=4>
 <font color=gray>
  
<?
####################
#페이지 리스트
#페이지 리스트의 첫 번째로 표시될 페이지가 몇 번째 페이지인지 구하는 부분이다

$start_page=(int)($current_page/$page_list_size)
* $page_list_size;

/*현재 페이지를 페이지 리스트 수로 나누면 현재 페이지가 몇 번째 페이지 리스트에 있는지 알게 된다
이 또한 0을 기준으로 하기에 형변환(타입 캐스팅)을 해주었다
형변환은 앞 강좌에서 배웠지만 위의 나누어지는 수가 1.2와 같이 유리수로 표시되기 때문이다
int(정수)형으로 형변환을 하면 소수점 자리가 사라진다
즉, 위에서 사용한 floor랑 같은 효과를 하게 되는 것이다
여기에 floor 함수를 취하거나 위의 floor를 형변환해도 상관없다
페이지 리스트의 마지막 페이지가 몇 번째 페이지인지 구하는 부분이다*/

$end_page=$start_page+$page_list_size-1;
if($total_page<$end_page) $end_page=$total_page;

/*보여주는 페이지 리스트 중에서 마지막 펭지가 되는 경우는 두 가지다
1. 페이지가 페이지 리스트 크기보다 더 많이 남아있을 때
10개씩 뿌려주는데 총 11페이지가 존재한다면 11페이지는 두 번째 목록 펭지에 뿌려진다
그렇다면 마지막 페이지 리스트는 10페이지 즉, 첫 번째 페이지+9번째 페이지이다
2. 10개씩 뿌려주는데 5페이지밖에 없다면?
마지막 리스트 페이지는 5페이지가 된다


이전 페이지 리스트 보여주기
페이지 리스트가 10인데 13번째 페이지에 있다면 두 번째 목록 페이지를 보고 있는 것이다
이전 목록 페이지로 가고 싶을 때 사용한다
이전 페이지 리스트가 필요할 때는 페이지 리스트의 첫 페이지가 페이지 리스트 수보다 클 때다
페이지가 적어도 페이지 리스트 수보다는 커야 이전 페이지 리스트가 존재할 테니깐 말이다
페이지 리스트의 수가 10인데 총 5페이지밖에 없다면 이전 페이지 리스트는 존재하지 않는다*/
$php_self="";
if($start_page>=$page_list_size) {

#이전 페이지 리스트값은 첫 번째 페이지 리스트에서 뒤로 리스트의 수만큼 이동하면 된다
#$page_size를 곱해주는 이유는 글 번호로 표시하기 위해서이다

$prev_list=($start_page-1)*$page_size;
echo "<a href=\"$php_self?no=$prev_list\">이전</a>\n";
}
#페이지 리스트를 출력 $no=($page_num-1)*$page_size;
for($i=$start_page; $i<=$end_page; $i++) {
$page=$page_size*$i; //페이지값을 no값으로 변환
$page_num=$i+1; //실제 페이지 값이 0부터 시작하므로 표시할 때는 1을 더해준다

if($no!=$page){ //현재 페이지가 아닐 경우만 링크를 표시
echo "<a href=\"$php_self?no=$page\">";
}

echo " $page_num "; //페이지를 표시
 
if($no!=$page) {
echo "</a>";
}
}
#다음 페이지 리스트가 필요할 때는 총 페이지가 미지막 리스트보다 클 때이다
#리스트를 다 뿌리고도 더 뿌려줄 페이지가 남았을 때 다음 버튼이 필요할 것이다
if($total_page>$end_page)
{
#다음 페이지 리스트는 마지막 리스트 페이지보다 한 페이지 뒤로 이동하면 된다
$next_list=($end_page+1)*$page_size;
echo "<a href=$php_self?no=$next_list>다음</a><p>";

}
?>
</font>
</td>
</tr>
</table>
<a href=write.php>글쓰기</a>
</center>
</body>
</html>  

이 질문에 댓글 쓰기 :

답변 1

게시판을 직접만들고 계신모양이네요.

notice 에러를 출력하지 않도록 해당 파일 상단에 설정하셔도 되고..

 

error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING ); 

 

또는 isset 으로 체크하신후 사용하시면 됩니다.

 

$id=$_GET['id']; $no=$_GET['no']; 

이 부분을 아래로 변경..

 

if(isset($_GET['id']))

    $id=$_GET['id'];

 

if(isset($_GET['no']))

    $no=$_GET['no'];

 

5쇄 발행 2013년 4월에 된 책을 사서 공부중입니다 오타도 없는데 에러가 나오네요.. 인터넷 찾아보니깐 php보안이 강화되서 바뀐게 있다고 하는데..
혹시 추천해주실만한 책있으신가요?

그리고 오류메시지 나옵니다
Notice: Undefined variable: no in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\cc\WebContent\read.php on line 78

77번째줄  <td width=280 align=left height=20>
78번째줄  <a href=list.php?no=<?=$no?>><font color=white>
79번째줄  [목록보기]</font></a>

답변을 작성하시기 전에 로그인 해주세요.
전체 123,681 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT