Section 05 01 DB num int not null
Section 05 01 공지사항 게시판 DB 테이블 필드 이름 타입 추가 사항 필드 설명 num int not null, auto_increment, primary key 일렬 번호 id varchar(10) not null 아이디 name varchar(10) not null 이름 subject varchar(100) not null 제목 content text not null 글 내용 regist_day varchar(20) 글 쓴 날짜 hit int 조회수 ip varchar(20) 접속 IP [표 13 -2] 공지사항 게시판 DB 테이블 (테이블 명 : notice_board) 8
Section 06 01 자유게시판 DB 테이블 만들기 메모장으로 다음을 타이핑한 다음 “c: ₩mysql₩bin” 폴더 밑에 “notice_board. sql”이름으로 저장 CREATE TABLE notice_board ( num int not null auto_increment, id varchar(10) not null, name varchar(10) not null, subject varchar(100) not null, content text not null, regist_day varchar(20), hit int, ip varchar(20), PRIMARY KEY (num) ); 명령 프롬프트에서 다음을 실행 C: ₩mysql₩bin> mysql -uphp 5 -p 1234 php 5_db < notice_board. sql 9
Section 07 01 공지사항 리플 DB 테이블 필드 이름 타입 추가 사항 필드 설명 num int not null, auto_increment, primary key 일렬 번호 parent int not null 리플의 부모 글 id varchar(10) not null 아이디 name varchar(20) not null 이름 content text not null 리플 내용 regist_day varchar(20) 리플 단 날짜 ip varchar(20) 접속 IP [표 13 -3] 리플 DB 테이블 (테이블 명 : notice_ripple) 10
Section 08 01 공지사항 리플 DB 테이블 만들기 메모장으로 다음을 타이핑한 다음 “c: ₩mysql₩bin” 폴더 밑에 “notice_ripple. sql”이름으로 저장 CREATE TABLE notice_ripple ( num int not null auto_increment, parent int not null, id varchar(10) not null, name varchar(10) not null, content text not null, regist_day varchar(20), ip varchar(20), PRIMARY KEY (num) ); 명령 프롬프트에서 다음을 실행 C: ₩mysql₩bin> mysql -uphp 5 -p 1234 php 5_db < notice_ripple. sql 11
Section 13 -1】list. php 01 【예제 02 공지사항 목록 보기 59 : $start = ($page - 1) * $scale; 61 : $number = $total_record - $start; 63 : for ($i=$start; $i<$start+$scale && $i < $total_record; $i++) 64 : { 65 : mysql_data_seek($result, $i); // 가져올 레코드로 포인터 이동 66 : $row = mysql_fetch_array($result); // 하나의 레코드 가 져오기 68 : $day = substr($row[regist_day], 0, 10); 69 : 70 : $sql = "select * from notice_ripple where parent = '$row[num]'"; 72 : $result 2 = mysql_query($sql, $connect); 73 : $num_ripple = mysql_num_rows($result 2); 75 : echo " <tr height=25> 77 : <td align=center>$number</td> 78 : <td><img src='img/record_id. gif' border=0> 12
Section 13 -1】list. php 01 【예제 02 81 : if ($num_ripple) echo color=blue>[$num_ripple]</font>"; 82 : echo " 83 : </a></td> 84 : <td align=center>$day</td> 85 : <td align=center>$row[hit]</td> 86 : <td align=center>$row[name] </td> 87 : </tr> 88 : <tr bgcolor='#CCCCCC' height=1> 89 : <td colspan='5'></td> 90 : </tr> 91 : "; 92 : $number--; 93 : } 13 " <font
Section 09 01 substr( ) 함수 string substr ( string, int start [, int length]) <? $str 1 = substr ("abcdef", 1); // "bcdef" 을 반환한다. $str 2 = substr ("abcdef", 2, 3); // "cde" 을 반환한다. /* 만약 start가 음수라면, 반환되는 문자열은 string의 끝에서부터 start 번째 부터 시작하는 문자열이 된다. */ $str 3 = substr ("abcdef", -1); // "f" 를 반환 $str 4 = substr ("abcdef", -4); // "cdef" 를 반환 $str 5 = substr ("abcdef", -3, 1); // "d" 를 반환 echo $str 1. " ". $str 2. " ". $str 3. " ". $str 4. " ". $str 5. " "; ? > 14
Section 13 -2】write_form. php 01 【예제 02 글쓰기 폼 양식 1 : <? 2 : session_start(); 4 : if ($userid != "admin") 5 : { echo(" 7 : <script> 8 : window. alert('관리자만 글을 쓸 수 있습니다. ') 9 : history. go(-1) 10 : </script> 11 : "); exit; 13 : } 14 : else 15 : { 16 : ? > 17 : <html> 18 : <head> 15
Section 13 -2】write_form. php 01 【예제 02 39 : <table width='100%' border=0 cellspacing=0 cellpadding=0 class='txt'> 40 : <tr height=25> 41 : <td align=right width=100>이름 </td> 42 : <td align=left> : <? echo $username ? > </td> </tr> 44 : </table> </td> </tr> 47 : <tr height=1 bgcolor=#5 AB 2 C 8><td colspan=2></td></tr> 48 : <tr bgcolor='#D 2 EAF 0' height=20> 49 : <td colspan=2> <b>하고 싶은 말을 남기세요. </b></td> </tr> 51 : <tr height=1 bgcolor=#5 AB 2 C 8><td colspan=5></td></tr> 52 : <tr><td colspan=2> 54 : <table width='100%' border=0 cellspacing=0 cellpadding=0 class='txt'> 55 : <tr> <td height=25> 제목 57 : <input style='font-size: 9 pt; border: 1 px solid' type='text' 58 : name='subject' size=50 maxlength=100></td> 16
Section 13 -2】write_form. php 01 【예제 02 // 중간 생략 71 : <tr height=1 bgcolor=#5 AB 2 C 8><td></tr> 72 : <tr> 73 : <td height=30 align=center valign=top bgcolor='FFFFFF'> 75 : <input type=image src='img/i_write. gif' align=absmiddle border=0> 76 : <a href='list. php'><img style='cursor: hand' 77 : src='img/i_list. gif' align=absmiddle border=0 ></a></td> 78 : </tr></table> </td> </tr> 82 : </table> </td> <tr> 85 : </form> 86 : </table> 87 : </body> 88 : </html> 89 : 90 : <? 91 : } 92 : ? > 17
Section 13 -3】insert. php 01 【예제 02 글 쓴 내용 DB 저장 1 : <? 2 : session_start(); // 중간 생략 24 : include ". . /dbconn. php"; // dconn. php 파일을 불러옴 26 : $regist_day = date("Y-m-d (H: i)"); // 현재의 날짜를 저장 27 : $ip = $REMOTE_ADDR; // 방문자의 IP 주소를 저장 28 : 29 : // 레코드 삽입 명령 30 : $sql = "insert into notice_board(id, name, subject, content, regist_day, hit, ip) "; 31 : $sql. = "values('$userid', '$username', '$subject', '$content', '$regist_day', 0, '$ip')"; 33 : mysql_query($sql, $connect); // $sql 에 저장된 명령 실행 35 : mysql_close(); // DB 연결 끊기 37 : Header("Location: list. php"); // list. php 로 이동 38 : ? > 18
Section 13 -4】view. php 01 【예제 02 글내용 보기 1 2 3 4 5 6 7 8 9 : <? : session_start(); : ? > : <html> : <head> : <title>: : PHP 프로그래밍 입문에 오신 것을 환영합니다~~ : : </title> : <link rel="stylesheet" href=". . /style. css" type="text/css"> : </head> : <body leftmargin="0" topmargin="0" marginwidth="0“ marginheight="0"> // 중간 생략 21 : <tr height=1 bgcolor=#5 AB 2 C 8><td></tr> 23 : <? 24 : include ". . /dbconn. php"; 26 : $sql = "select * from notice_board where num=$num"; 28 : $result = mysql_query($sql, $connect); 19
Section 13 -4】view. php 01 【예제 02 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 : $row = mysql_fetch_array($result); : : $day = substr($row[regist_day], 0, 10); : : $content = str_replace("n", " ", $row[content]); : $content = str_replace(" ", " ", $content); : $subject = str_replace(" ", " ", $row[subject]); : : $hit = $row[hit]; : $hit++; : : $sql = "update notice_board set hit=$hit where num=$num"; : mysql_query($sql, $connect); : ? > : <tr bgcolor="#D 2 EAF 0" height=35> : <td> <b><? echo $subject ? ></td> </tr> 20
Section 13 -4】view. php 01 【예제 02 69 : <tr height=1 bgcolor=#5 AB 2 C 8><td></tr> 70 : <tr> <td> 72 : <? 73 : $sql = "select * from notice_ripple where parent=$num order by num desc"; 74 : $result = mysql_query($sql, $connect); 75 : $num_ripple = mysql_num_rows($result); 77 : if($num_ripple) 78 : { 79 : while ( $row = mysql_fetch_array($result) ) 80 : { 81 : $ripple_day = $row[regist_day]; 82 : $ripple_day = substr($ripple_day, 5, 5); 83 : 84 : $ripple_content = str_replace("n", " ", $row[content]); 85 : $ripple_content = str_replace(" ", " ", $ripple_content); 86 : $ripple_ip = $row[ip]; 21
Section 13 -4】view. php 01 【예제 02 87 : $ripple_num = $row[num]; 88 : $ripple_id = $row[id]; 89 : $ripple_name = $row[name]; 91 : echo " <table width=100% cellpadding=0> 93 : <tr height=20> 94 : <td width=10% align=center> $ripple_name </td> 95 : <td width=80%% align=left> $ripple_content</td> 96 : <td width=10% align=left> $ripple_day "; 98 : if ($userid == $ripple_id or $userid=="admin") 99 : { echo " <a href='delete_ripple. php? num=$num& ripple_num= $ripple_num'>D "; 103 : } 104 : echo " </td> </tr> <tr height=1 bgcolor=#5 AB 2 C 8> 108 : <td colspan=3></td> </tr> </table> "; 112 : } 113 : } 115 : mysql_close(); 116 : ? > 22
Section 13 -4】view. php 01 【예제 02 123 124 125 : <? : echo " : <form method=post action='insert_ripple. php? num=$num'> : <table align=center border=0 cellspacing=0 cellpadding=0 width=766> 126 : <tr><td colspan=2> 이름 : $username </td></tr> 127 : <tr height=5><td colspan=2> </td></tr> 128 : <tr><td><textarea style='font-size: 9 pt; border: 1 px solid‘ name='content' 129 : style=background-image: url('img/bbs_text_line. gif'); cols=110 rows=4 wrap=virtual></textarea></td> 131 : <td align=right><input type=image src='img/regist. gif'></td> 132 : </tr> </table> 136 : </form> 137 : "; 138 : ? > 23
Section 13 -4】view. php 01 【예제 02 145 : <td align=center> 146 : <? 147 : if ($userid == "admin") 148 : { echo " 150 : <a href='modify_form. php? num=$num&page=$page'> 151 : <img src='img/i_edit. gif' border=0> </a> 152 : <a href='delete. php? num=$num&page=$page'> 153 : <img src='img/i_del. gif' border=0> </a> 154 : "; 155 : } 156 : ? > 157 : <a href="list. php? page=<? echo $page ? >"> <img src='img/i_list. gif' border=0> 158 : </a></td> </tr> 160 : </table> 161 : </body> 162 : </html> 24
Section 13 -5】modify_form. php 01 【예제 02 글 수정 폼 양식 1 : <? 2 : session_start(); 4 : if ($userid != "admin") 5 : { echo(" 7 : <script> 8 : window. alert('관리자만 수정할 수 있습니다. ') 9 : history. go(-1) 10 : </script> 11 : "); exit; 13 : } 14 : else 15 : { 17 : include ". . /dbconn. php"; 18 : $sql = "select * from notice_board where num=$num"; 19 : $result = mysql_query($sql, $connect); 25
Section 13 -5】modify_form. php 01 【예제 02 21 23 24 25 26 27 28 29 30 31 : $row = mysql_fetch_array($result); : $subject = $row[subject]; : $content = $row[content]; : ? > : <html> : <head> : <title>: : PHP 프로그래밍 입문에 오신 것을 환영합니다~~ : : </title> : <link rel='stylesheet' href='. . /style. css' type='text/css'> : </head> : <body leftmargin='0' topmargin='0' marginwidth='0‘ marginheight='0'> 32 : 33 : <table border=0 cellspacing=0 cellpdding=0 width='776‘ align='center'> 34 : <form name='writeform‘ action='modify. php? num=<? echo $num ? > 35 : &page=<? echo $page ? >‘ method='post'> 26
Section 13 -5】modify_form. php 01 【예제 02 54 : <tr height=25> 55 : <td align=right width=100>이름 </td> 56 : <td align=left> : <? echo $username ? > </td></tr></table> 59 : </td> 60 : </tr> 61 : <tr height=1 bgcolor=#5 AB 2 C 8><td colspan=2></td></tr> 62 : <tr bgcolor='#D 2 EAF 0' height=20> 63 : <td colspan=2> <b>하고 싶은 말을 남기세요. </b> </td></tr> 65 : <tr height=1 bgcolor=#5 AB 2 C 8><td colspan=5></td></tr> 69 : <tr> 70 : <td height=25> 제목 71 : <input style='font-size: 9 pt; border: 1 px solid' type='text' 72 : name='subject' size=50 maxlength=100 73 : value='<? 27 echo $subject ? >'></td>
Section 13 -6】modify. php 01 【예제 02 글 수정 DB 업데이트 1 : <? 2 : session_start(); 4 : if ($userid=="admin") 5 : { // 중간 생략 26 : include ". . /dbconn. php"; 28 : $regist_day = date("Y-m-d (H: i)"); // 현재의 날짜 저장 29 : $ip = $REMOTE_ADDR; // 방문자의 IP 주소를 저장 31 : 32 : $sql = "update notice_board set subject='$subject', "; 33 : $sql. = "content='$content' where num=$num"; 35 : mysql_query($sql, $connect); 36 : mysql_close(); 37 : } 39 : Header("Location: list. php? num=$num&page=$page"); 40 : ? > 28
Section 13 -7】delete. php 01 【예제 02 글 삭제 1 : <? 2 : session_start(); 세션변수 3 : 4 : if ($userid == "admin") 5 : { 6 : include ". . /dbconn. php"; 7 : 8 : $sql = "delete from notice_board where num = $num"; 9 : mysql_query($sql, $connect); 10 : mysql_close(); 11 : } 12 : 13 : Header("Location: list. php? page=$page"); 14 : ? > 29
Section 13 -8】insert_ripple. php 01 【예제 02 리플 글 삽입 1 : <? 2 : session_start(); 4 : if(!$userid) { 5 : echo(" 6 : <script> 7 : window. alert('회원가입 후 이용하세요. ') 8 : history. go(-1) 9 : </script> 10 : "); 11 : exit; 12 : } 13 : 세션변수 24 : include ". . /dbconn. php"; 26 : $id = $userid; 27 : $name = $username; 30
Section 13 -8】insert_ripple. php 01 【예제 02 29 : $regist_day = date("Y-m-d (H: i)"); // 현재의 날짜 저장 30 : $ip = $REMOTE_ADDR; // 방문자의 IP 주소를 저장 31 : 32 : // 레코드 삽입 명령 33 : $sql = "insert into notice_ripple(parent, id, name, content, regist_day, ip) "; 34 : $sql. = "values('$num', '$id', '$name', '$content', '$regist_day', '$ip')"; 35 : 36 : mysql_query($sql, $connect); // $sql 에 저장된 명령 실행 37 : 38 : mysql_close(); // DB 연결 끊기 39 : 40 : Header("Location: view. php? num=$num"); // view. php 로 이동 41 : ? > 31
Section 13 -9】delete_ripple. php 01 【예제 02 리플 글 삭제 1 : <? 2 : include ". . /dbconn. php"; 3 : 4 : $sql = "delete from notice_ripple where num = $ripple_num"; 5 : mysql_query($sql, $connect); 6 : Header("Location: view. php? num=$num"); 7 : mysql_close(); 8 : ? > 32
- Slides: 32