Data Base Web Programming PHP
접속하기 서버에 접속한다 DB접속하기 SSH Secure Shell 프로그램 이용 Host : et2.hknu.ac.kr Id : t학번 Pwd : a12345 <- 초기값 DB접속하기 mysql –uhk학번 -pa12345 hk학번 ex) mysql –uhk2009123456 -pa12345 hk2009123456
“mysql”에 접속한다. mysql –uhk2009123456 -pa12345 hk2009123456
“addr_list.html” 수정 <? $dbconn = mysql_connect("localhost",“hk2009123456","a12345"); $status = mysql_select_db(“hke200912345612345"); // DB명 = ID와 같음 if (!$status) { echo("DB_ERROR"); exit; } // 주소읽기 $sqry1 = " select * from addr "; $result = mysql_query($sqry1); $rows = mysql_num_rows($result); ?>
for($i = 1; $i <= $rows; $i++) { <td><a href='./addr_view.html?seq=<?echo($row->seq)?>'><?echo($row->seq)?></a></td> 수정 <? for($i = 1; $i <= $rows; $i++) { $row = mysql_fetch_object($result); ?> <tr> <td><?echo($row->seq)?></td> <td><?echo($row->na)?></td> <td><?echo($row->hp)?></td> <td><?echo($row->email)?></td> </tr> } </table> <a href="./addr.html">주소 입력</a> </BODY> </HTML> <HTML> <HEAD> <TITLE>주소등록</TITLE> </HEAD> <BODY> <table border=1> <tr> <td>순번</td> <td>이름</td> <td>핸드폰</td> <td>이메일</td> </tr>
“addr_view.html” 신규입력 <? // ID PWD $dbconn = mysql_connect("localhost",“hk2009123456","a12345"); $status = mysql_select_db(“hk2009123456"); // DB명 = ID와 같음 if (!$status) { echo("DB_ERROR"); exit; } // 주소읽기 $sqry1 = " select * from addr where seq=$seq "; $result = mysql_query($sqry1); $row = mysql_fetch_object($result); ?>
<TITLE>주소상세보기</TITLE> </HEAD> <BODY> <table border=1> <tr> <td>순번</td> <td><?echo($row->seq)?></td> </tr> <td>이름</td> <td><?echo($row->na)?></td> <td>핸드폰</td> <td><?echo($row->hp)?></td> <td>이메일</td> <td><?echo($row->email)?></td> <td>주소</td> <td><?echo($row->addr)?></td> </table> <a href="./addr.html">주소 입력</a><br> <a href="./addr_rewrite.html?seq=<?echo($row->seq)?>">주소 수정</a><br> <a href="./addr_list.html">주소 리스트</a> </BODY> </HTML>
“Web에서 확인한 경우” http://et2.hknu.ac.kr/~e2009123456/addr_list.html 클릭
http://et2.hknu.ac.kr/~e2009123456/addr_view.html?seq=1
“addr_rewrite.html” 작성하기 <? // ID PWD $dbconn = mysql_connect("localhost",“hk2009123456","a12345"); $status = mysql_select_db(“hk2009123456"); // DB명 = ID와 같음 if (!$status) { echo("DB_ERROR"); exit; } // 주소읽기 $sqry1 = " select * from addr where seq=$seq "; $result = mysql_query($sqry1); $row = mysql_fetch_object($result); ?>
<HTML> <HEAD> <TITLE>주소등록</TITLE> </HEAD> <BODY> <Form method="post" action="addr_rewrite.php"> 이름 : <input type="text" name="na" size="10" value="<?echo($row->na)?>"><br> 핸드폰 : <input type="text" name="hp" size="20" value="<?echo($row->hp)?>"><br> 전화번호 : <input type="text" name="tel" size="20" value="<?echo($row->tel)?>"><br> 주소 : <input type="text" name="addr" size="50" value="<?echo($row->addr)?>"><br> 이메일 : <input type="text" name="email" size="30" value="<?echo($row->email)?>"><br> <input type="submit" value="전송"> <input type="reset" value="다시쓰기"> <input type="hidden" name="seq" value="<?echo($row->seq)?>"> </form> </BODY> </HTML>
“addr_rewrtie.php”작성 <? // ID PWD $dbconn = mysql_connect("localhost","p12345","a12345"); $status = mysql_select_db("p12345"); // DB명 = ID와 같음 if (!$status) { echo("DB_ERROR"); exit; } $sqry = " update addr set na = '$na' , hp = '$hp', tel='$tel', addr='$addr', email='$email' where seq=$seq "; $result=mysql_query($sqry); if (!$result) echo("update ERROR"); echo("저장 성공 "); echo("<a href='./addr.html'>다시 입력</a><br>"); echo("<a href='./addr_list.html'>목록보기</a>"); ?>
“WEB에서 확인” http://et2.hknu.ac.kr/~e2009123456/addr_view.html?seq=1 클릭
http://et2.hknu.ac.kr/~e2009123456/addr_rewrite.html?seq=1 http://et2.hknu.ac.kr/~e2009123456/addr_rewrite.html?seq=1
리스트 보기에서 클릭하여 확인하기 http://et2.hknu.ac.kr/~e2009123456/addr_view.html?seq=1