SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
간단한 방명록 제작
     (두번째)


웹 데이터 베이스
서비스 정의
• 사이트에 방문한 방문객으로 하여금 간단한 글을
  남기게 한다.
• 한 페이지당 보여지는 게시물은 5개
    • 페이지 이동을 위한 버튼 제공
• 누구나 글을 볼 수 있다.
• 글을 쓰기 위해서는 사용자명을 입력한다.
• 게시물에 대해 암호를 주어 해당 암호를 알고 있
  으면 삭제할 수 있다.




한림대학교 웹데이터베이스 - 이윤환
TABLE
CREATE TABLE gbook (
      gb_id        int unsigned NOT NULL
                   AUTO_INCREMENT PRIMARY KEY,
      writer       varchar(50)   NOT NULL,
      regDate            datetime     NOT NULL,
      comments           text         NOT NULL,
      userpwd            char(41)     NOT NULL
);




한림대학교 웹데이터베이스 - 이윤환
글 수정과 삭제
action.php 에 URL을 통해 (GET 방식) action 변
수 값에 전달된 값(update, delete)에 따라 수정과
삭제를 결정한다.
action.php는 사용자의 암호를 물어보고 POST 방
식으로validate_user.php 로 전달한다.
주어진 글에 대한 암호가 일치할 경우 수정 및 삭제
페이지로 이동한다.
 • 수정의 경우 update.php 로 이동
 • 삭제의 경우 delete.php로 이동




한림대학교 웹데이터베이스 - 이윤환
ACTION.PHP
유입 링크
 • action.php?action=update&id=글ID&start=전달하는페이지시작값
 • action.php?action=delete&id=글ID&start=전달하는페이지시작값
GET으로 전달되는 값 처리
 • $action = $_GET["action"];
 • $id = $_GET["id"];
 • $start = $_GET["start"];
Hidden을 이용하여 validate_user.php 에 값 전
달
 • <input type="hidden" name="action" value="<?php echo
   $action;?>" />
 • <input type="hidden" name="id" value="<?php echo $id;?>" />
 • <input type="hidden" name="start" value="<?php echo $start;?>"
   />


한림대학교 웹데이터베이스 - 이윤환
VALIDATE_USER.PHP
action.php 에서 입력한 암호와 게시물의 암호가 같은
지 검사
action 값에 따라 수정과 삭제 페이지로 이동
변수 처리
 • $action = $_POST["action"];
 • $id = $_POST["id"];
 • $start = $_POST["start"];
암호 검사 부분
 • 기존 암호 가져오기
     • $sql = "SELECT userpwd FROM gbook WHERE gb_id = " . $id;
     • $result = mysql_query($sql);
     • $isHere = mysql_num_rows($result);
     • if($isHere) {
              $storedPwd = mysql_result($result, 0, 0);


한림대학교 웹데이터베이스 - 이윤환
VALIDATE_USER.PHP
 • 입력 암호의 암호화
     • $sql = "SELECT password('" . trim($_POST["getPWD"]) . "');";
     • $result = mysql_query($sql);
     • $inputPwd = mysql_result($result, 0, 0);
 • 암호 비교
     • if(strcmp($storedPwd, $inputPwd))
          • strcmp 함수는 두 문자열을 비교하여 같으면 0 반환

페이지 이동 switch($action) { case 'update' :
                  ?>
                         // 이동을 위한 JavaScript
                  <?php
                                 break;
                         case 'delete' :
                  ?>
                         // 이동을 위한 JavaScript
                  <?php
                                 break;
                  }
한림대학교 웹데이터베이스 - 이윤환
글 수정
입력 변수와 점검
 $action = $_GET["action"];
 $id = $_GET["id"];
 $start = $_GET["start"];

 if(isset($_GET["action"]) AND isset($_GET["id"]) AND
 isset($_GET["start"])) {

기존 내용 가져오기
$sql = "SELECT gb_id, writer, comments FROM gbook WHERE
gb_id=" . $id;
$result = mysql_query($sql);
$rows = mysql_fetch_array($result, MYSQL_ASSOC);




한림대학교 웹데이터베이스 - 이윤환
글 수정
기본값 설정
    <input id="getID" name="getID" type="text" size="20"
    maxlength="20" value="<?php echo $rows["writer"];?>" />
    …
    <textarea id="getComments" name="getComments"
    rows="10" cols="40"><?php echo
    $rows["comments"];?></textarea>




hidden을 통한 값 전달
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input type="hidden" name="start" value="<?php echo $start;?>" />




한림대학교 웹데이터베이스 - 이윤환
글 수정 처리
폼 값 검정(Form Validation) – 글쓰기와 동일
수정을 위한 SQL – UPDATE
   $sql = "UPDATE gbook SET
           writer='" . $getID . "',
           comments='" . $getComments . "',
           userPwd=password('" . $getPWD . "')
           WHERE gb_id = " . $_POST["id"];


돌아가기
echo "<script type="text/javascript">n";
echo " location.href='list.php?start=" . $_POST["start"] . "';n";
echo "</script>n";
exit;



한림대학교 웹데이터베이스 - 이윤환
글 삭제
삭제 여부 재확인
 <script type="text/javascript">
 var isDel = confirm("정말로 삭제하시겠습니까?");
 if(!isDel) {
          location.href='list.php?start=' + '<?php echo $start;?>';
 }
 </script>

삭제를 위한 SQL – DELETE
   $sql = "DELETE FROM gbook WHERE gb_id = " . $id;


돌아가기
  <script type="text/javascript">
          alert("삭제하였습니다.");
          location.href='list.php?start=' + '<?php echo
  $start;?>';
  </script>
한림대학교 웹데이터베이스 - 이윤환
수고하셨습니다.
PHP 를 사용하는 방법에 대해 한학기간 살펴봤습니
다.
기말과제는 로그인한 사용자만 글쓰기가 가능하고
그렇지 않은 사용자는 읽을 수 있는 방명록을 만드
시면 됩니다.
http://openx3.tistory.com 이나 페이스북 페이
지 “Web 개발해 봅시다 – 한림대학교”를 통해 궁
금한 것 있으면 언제든 연락주시기 바랍니다.




한림대학교 웹데이터베이스 - 이윤환

Weitere ähnliche Inhalte

Was ist angesagt?

Web vulnerability seminar4
Web vulnerability seminar4Web vulnerability seminar4
Web vulnerability seminar4Sakuya Izayoi
 
PHP 함수와 제어구조
PHP 함수와 제어구조PHP 함수와 제어구조
PHP 함수와 제어구조Yoonwhan Lee
 
Web vulnerability seminar3
Web vulnerability seminar3Web vulnerability seminar3
Web vulnerability seminar3Sakuya Izayoi
 
Node.js + Express + MongoDB
Node.js + Express + MongoDBNode.js + Express + MongoDB
Node.js + Express + MongoDBVincent Park
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4성일 한
 
레일스 환경 변수
레일스 환경 변수레일스 환경 변수
레일스 환경 변수Eugene Park
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device accessJinKyoungHeo
 
MySQL delete.update
MySQL delete.updateMySQL delete.update
MySQL delete.updateHoyoung Jung
 
5-4. html5 offline and storage
5-4. html5 offline and storage5-4. html5 offline and storage
5-4. html5 offline and storageJinKyoungHeo
 
웹 개발 스터디 01 - MySQL
웹 개발 스터디 01 - MySQL웹 개발 스터디 01 - MySQL
웹 개발 스터디 01 - MySQLYu Yongwoo
 
vine webdev
vine webdevvine webdev
vine webdevdcfc1997
 
5-1. html5 graphics
5-1. html5 graphics5-1. html5 graphics
5-1. html5 graphicsJinKyoungHeo
 

Was ist angesagt? (20)

Web vulnerability seminar4
Web vulnerability seminar4Web vulnerability seminar4
Web vulnerability seminar4
 
PHP 함수와 제어구조
PHP 함수와 제어구조PHP 함수와 제어구조
PHP 함수와 제어구조
 
Hacosa j query 3th
Hacosa j query 3thHacosa j query 3th
Hacosa j query 3th
 
Web vulnerability seminar3
Web vulnerability seminar3Web vulnerability seminar3
Web vulnerability seminar3
 
Node.js + Express + MongoDB
Node.js + Express + MongoDBNode.js + Express + MongoDB
Node.js + Express + MongoDB
 
Hacosa j query 10th
Hacosa j query 10thHacosa j query 10th
Hacosa j query 10th
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
 
레일스 환경 변수
레일스 환경 변수레일스 환경 변수
레일스 환경 변수
 
MySQL JOIN
MySQL JOINMySQL JOIN
MySQL JOIN
 
Hacosa j query 4th
Hacosa j query 4thHacosa j query 4th
Hacosa j query 4th
 
PHP 기초 문법
PHP 기초 문법PHP 기초 문법
PHP 기초 문법
 
php 시작하기
php 시작하기php 시작하기
php 시작하기
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device access
 
MySQL delete.update
MySQL delete.updateMySQL delete.update
MySQL delete.update
 
5-4. html5 offline and storage
5-4. html5 offline and storage5-4. html5 offline and storage
5-4. html5 offline and storage
 
4-3. jquery
4-3. jquery4-3. jquery
4-3. jquery
 
웹 개발 스터디 01 - MySQL
웹 개발 스터디 01 - MySQL웹 개발 스터디 01 - MySQL
웹 개발 스터디 01 - MySQL
 
vine webdev
vine webdevvine webdev
vine webdev
 
5-1. html5 graphics
5-1. html5 graphics5-1. html5 graphics
5-1. html5 graphics
 

Andere mochten auch

Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...
Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...
Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...Suk Namgoong
 
역전야매액틴
역전야매액틴역전야매액틴
역전야매액틴Suk Namgoong
 
Cell Biology Lecture #2
Cell Biology Lecture #2Cell Biology Lecture #2
Cell Biology Lecture #2Suk Namgoong
 
Cell biology Lecture 6
Cell biology Lecture 6Cell biology Lecture 6
Cell biology Lecture 6Suk Namgoong
 
Linux Cluster and Distributed Resource Manager
Linux Cluster and Distributed Resource ManagerLinux Cluster and Distributed Resource Manager
Linux Cluster and Distributed Resource ManagerHong ChangBum
 
통계자료분석을 ㅇ
통계자료분석을 ㅇ통계자료분석을 ㅇ
통계자료분석을 ㅇYoonwhan Lee
 
Blaas nieuw leven in je PC met Linux
Blaas nieuw leven in je PC met LinuxBlaas nieuw leven in je PC met Linux
Blaas nieuw leven in je PC met LinuxJoachim Jacob
 
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...Hong ChangBum
 
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...Joachim Jacob
 
Chapter 2, 선형 변환과 행렬 1/2
Chapter 2, 선형 변환과 행렬 1/2Chapter 2, 선형 변환과 행렬 1/2
Chapter 2, 선형 변환과 행렬 1/2Thisisone Lee
 
Web2.0 & Bioinformatics
Web2.0 & BioinformaticsWeb2.0 & Bioinformatics
Web2.0 & BioinformaticsHong ChangBum
 

Andere mochten auch (20)

Goode
GoodeGoode
Goode
 
Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...
Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...
Rocket Launcher Mechanism of Collaborative Actin Assembly Defined by Single-M...
 
Cell culture 05
Cell culture 05Cell culture 05
Cell culture 05
 
역전야매액틴
역전야매액틴역전야매액틴
역전야매액틴
 
Cell Biology Lecture #2
Cell Biology Lecture #2Cell Biology Lecture #2
Cell Biology Lecture #2
 
Cell biology Lecture 6
Cell biology Lecture 6Cell biology Lecture 6
Cell biology Lecture 6
 
The Galaxy toolshed
The Galaxy toolshedThe Galaxy toolshed
The Galaxy toolshed
 
Linux Cluster and Distributed Resource Manager
Linux Cluster and Distributed Resource ManagerLinux Cluster and Distributed Resource Manager
Linux Cluster and Distributed Resource Manager
 
통계자료분석을 ㅇ
통계자료분석을 ㅇ통계자료분석을 ㅇ
통계자료분석을 ㅇ
 
DTC Companies List
DTC Companies ListDTC Companies List
DTC Companies List
 
Platform Day
Platform DayPlatform Day
Platform Day
 
Cluster Drm
Cluster DrmCluster Drm
Cluster Drm
 
Blaas nieuw leven in je PC met Linux
Blaas nieuw leven in je PC met LinuxBlaas nieuw leven in je PC met Linux
Blaas nieuw leven in je PC met Linux
 
Web2.0
Web2.0Web2.0
Web2.0
 
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...
Genome Wide SNP Analysis for Inferring the Population Structure and Genetic H...
 
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...
Part 6 of RNA-seq for DE analysis: Detecting biology from differential expres...
 
How to genome
How to genomeHow to genome
How to genome
 
Make
MakeMake
Make
 
Chapter 2, 선형 변환과 행렬 1/2
Chapter 2, 선형 변환과 행렬 1/2Chapter 2, 선형 변환과 행렬 1/2
Chapter 2, 선형 변환과 행렬 1/2
 
Web2.0 & Bioinformatics
Web2.0 & BioinformaticsWeb2.0 & Bioinformatics
Web2.0 & Bioinformatics
 

Ähnlich wie Class10

11주차 간단한 방명록 제작
11주차 간단한 방명록 제작11주차 간단한 방명록 제작
11주차 간단한 방명록 제작Yoonwhan Lee
 
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기Jeado Ko
 
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)Ukjae Jeong
 
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우XpressEngine
 
[APM] Homepage bbs
[APM] Homepage bbs[APM] Homepage bbs
[APM] Homepage bbsKim Heejin
 
Html5&css 3장
Html5&css 3장Html5&css 3장
Html5&css 3장홍준 김
 
[115] clean fe development_윤지수
[115] clean fe development_윤지수[115] clean fe development_윤지수
[115] clean fe development_윤지수NAVER D2
 
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화Jinhwa Ko
 
Webframeworks angular js 세미나
Webframeworks angular js 세미나Webframeworks angular js 세미나
Webframeworks angular js 세미나WebFrameworks
 
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발Dreamweaver CS5.5 를 이용한 jQueryMobile 개발
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발JongKwang Kim
 
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)DK Lee
 
Apache solr소개 20120629
Apache solr소개 20120629Apache solr소개 20120629
Apache solr소개 20120629Dosang Yoon
 
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Sungjoon Yoon
 
Xe3.0 frontend validator
Xe3.0 frontend validatorXe3.0 frontend validator
Xe3.0 frontend validator승훈 오
 
Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료joonseokkim11
 
Daejeon IT Developer Conference Hibernate3
Daejeon IT Developer Conference Hibernate3Daejeon IT Developer Conference Hibernate3
Daejeon IT Developer Conference Hibernate3plusperson
 

Ähnlich wie Class10 (20)

11주차 간단한 방명록 제작
11주차 간단한 방명록 제작11주차 간단한 방명록 제작
11주차 간단한 방명록 제작
 
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
 
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)
현대고등학교 PHP 강의 - 7,8차시 (설리번 프로젝트)
 
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우
XE 오픈 세미나(2014-06-28) - (2/3) 레이아웃 제작 노하우
 
[APM] Homepage bbs
[APM] Homepage bbs[APM] Homepage bbs
[APM] Homepage bbs
 
Html5&css 3장
Html5&css 3장Html5&css 3장
Html5&css 3장
 
Meteor2015 codelab
Meteor2015 codelab Meteor2015 codelab
Meteor2015 codelab
 
[115] clean fe development_윤지수
[115] clean fe development_윤지수[115] clean fe development_윤지수
[115] clean fe development_윤지수
 
Hacosa jquery 1th
Hacosa jquery 1thHacosa jquery 1th
Hacosa jquery 1th
 
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화
XE 레이아웃 제작 실무 노하우 1 - XECon2014 by 고진화
 
Webframeworks angular js 세미나
Webframeworks angular js 세미나Webframeworks angular js 세미나
Webframeworks angular js 세미나
 
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발Dreamweaver CS5.5 를 이용한 jQueryMobile 개발
Dreamweaver CS5.5 를 이용한 jQueryMobile 개발
 
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)
자바 웹 개발 시작하기 (7주차 : 국제화, 확인검증, 예외처리)
 
Apache solr소개 20120629
Apache solr소개 20120629Apache solr소개 20120629
Apache solr소개 20120629
 
Hacosa j query 11th
Hacosa j query 11thHacosa j query 11th
Hacosa j query 11th
 
Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)Ksug 세미나 (윤성준) (20121208)
Ksug 세미나 (윤성준) (20121208)
 
Xe3.0 frontend validator
Xe3.0 frontend validatorXe3.0 frontend validator
Xe3.0 frontend validator
 
Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료
 
Daejeon IT Developer Conference Hibernate3
Daejeon IT Developer Conference Hibernate3Daejeon IT Developer Conference Hibernate3
Daejeon IT Developer Conference Hibernate3
 
Xe hack
Xe hackXe hack
Xe hack
 

Mehr von Yoonwhan Lee

R 기초 : R Basics
R 기초 : R BasicsR 기초 : R Basics
R 기초 : R BasicsYoonwhan Lee
 
03.기술통계 자료의 중심과 퍼진정도
03.기술통계 자료의 중심과 퍼진정도03.기술통계 자료의 중심과 퍼진정도
03.기술통계 자료의 중심과 퍼진정도Yoonwhan Lee
 
02.자료다루기
02.자료다루기02.자료다루기
02.자료다루기Yoonwhan Lee
 
13.상관과 회귀
13.상관과 회귀13.상관과 회귀
13.상관과 회귀Yoonwhan Lee
 
12.세표본 이상의 평균비교
12.세표본 이상의 평균비교12.세표본 이상의 평균비교
12.세표본 이상의 평균비교Yoonwhan Lee
 
11.두표본의 평균비교
11.두표본의 평균비교11.두표본의 평균비교
11.두표본의 평균비교Yoonwhan Lee
 
10.단일표본 평균 모비율
10.단일표본 평균 모비율10.단일표본 평균 모비율
10.단일표본 평균 모비율Yoonwhan Lee
 
09.통계적가설검정
09.통계적가설검정09.통계적가설검정
09.통계적가설검정Yoonwhan Lee
 
00.통계학입문
00.통계학입문00.통계학입문
00.통계학입문Yoonwhan Lee
 
14.범주형자료분석
14.범주형자료분석14.범주형자료분석
14.범주형자료분석Yoonwhan Lee
 
Smart work 자료 1
Smart work 자료 1Smart work 자료 1
Smart work 자료 1Yoonwhan Lee
 
통계자료 분석을 위한 R
통계자료 분석을 위한 R통계자료 분석을 위한 R
통계자료 분석을 위한 RYoonwhan Lee
 
쿠키를 통해 구현해보는 간단한 로그인 과정
쿠키를 통해 구현해보는 간단한 로그인 과정쿠키를 통해 구현해보는 간단한 로그인 과정
쿠키를 통해 구현해보는 간단한 로그인 과정Yoonwhan Lee
 
에버노트와 드롭박스 설치
에버노트와 드롭박스 설치에버노트와 드롭박스 설치
에버노트와 드롭박스 설치Yoonwhan Lee
 

Mehr von Yoonwhan Lee (20)

R 기초 : R Basics
R 기초 : R BasicsR 기초 : R Basics
R 기초 : R Basics
 
03.기술통계 자료의 중심과 퍼진정도
03.기술통계 자료의 중심과 퍼진정도03.기술통계 자료의 중심과 퍼진정도
03.기술통계 자료의 중심과 퍼진정도
 
02.자료다루기
02.자료다루기02.자료다루기
02.자료다루기
 
01.r 기초
01.r 기초01.r 기초
01.r 기초
 
13.상관과 회귀
13.상관과 회귀13.상관과 회귀
13.상관과 회귀
 
12.세표본 이상의 평균비교
12.세표본 이상의 평균비교12.세표본 이상의 평균비교
12.세표본 이상의 평균비교
 
11.두표본의 평균비교
11.두표본의 평균비교11.두표본의 평균비교
11.두표본의 평균비교
 
10.단일표본 평균 모비율
10.단일표본 평균 모비율10.단일표본 평균 모비율
10.단일표본 평균 모비율
 
09.통계적가설검정
09.통계적가설검정09.통계적가설검정
09.통계적가설검정
 
08.추정
08.추정08.추정
08.추정
 
07.표본분포
07.표본분포07.표본분포
07.표본분포
 
06.확률분포
06.확률분포06.확률분포
06.확률분포
 
05.확률
05.확률05.확률
05.확률
 
00.통계학입문
00.통계학입문00.통계학입문
00.통계학입문
 
14.범주형자료분석
14.범주형자료분석14.범주형자료분석
14.범주형자료분석
 
Smart work 자료 1
Smart work 자료 1Smart work 자료 1
Smart work 자료 1
 
통계자료 분석을 위한 R
통계자료 분석을 위한 R통계자료 분석을 위한 R
통계자료 분석을 위한 R
 
추정
추정추정
추정
 
쿠키를 통해 구현해보는 간단한 로그인 과정
쿠키를 통해 구현해보는 간단한 로그인 과정쿠키를 통해 구현해보는 간단한 로그인 과정
쿠키를 통해 구현해보는 간단한 로그인 과정
 
에버노트와 드롭박스 설치
에버노트와 드롭박스 설치에버노트와 드롭박스 설치
에버노트와 드롭박스 설치
 

Class10

  • 1. 간단한 방명록 제작 (두번째) 웹 데이터 베이스
  • 2. 서비스 정의 • 사이트에 방문한 방문객으로 하여금 간단한 글을 남기게 한다. • 한 페이지당 보여지는 게시물은 5개 • 페이지 이동을 위한 버튼 제공 • 누구나 글을 볼 수 있다. • 글을 쓰기 위해서는 사용자명을 입력한다. • 게시물에 대해 암호를 주어 해당 암호를 알고 있 으면 삭제할 수 있다. 한림대학교 웹데이터베이스 - 이윤환
  • 3. TABLE CREATE TABLE gbook ( gb_id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, writer varchar(50) NOT NULL, regDate datetime NOT NULL, comments text NOT NULL, userpwd char(41) NOT NULL ); 한림대학교 웹데이터베이스 - 이윤환
  • 4. 글 수정과 삭제 action.php 에 URL을 통해 (GET 방식) action 변 수 값에 전달된 값(update, delete)에 따라 수정과 삭제를 결정한다. action.php는 사용자의 암호를 물어보고 POST 방 식으로validate_user.php 로 전달한다. 주어진 글에 대한 암호가 일치할 경우 수정 및 삭제 페이지로 이동한다. • 수정의 경우 update.php 로 이동 • 삭제의 경우 delete.php로 이동 한림대학교 웹데이터베이스 - 이윤환
  • 5. ACTION.PHP 유입 링크 • action.php?action=update&id=글ID&start=전달하는페이지시작값 • action.php?action=delete&id=글ID&start=전달하는페이지시작값 GET으로 전달되는 값 처리 • $action = $_GET["action"]; • $id = $_GET["id"]; • $start = $_GET["start"]; Hidden을 이용하여 validate_user.php 에 값 전 달 • <input type="hidden" name="action" value="<?php echo $action;?>" /> • <input type="hidden" name="id" value="<?php echo $id;?>" /> • <input type="hidden" name="start" value="<?php echo $start;?>" /> 한림대학교 웹데이터베이스 - 이윤환
  • 6. VALIDATE_USER.PHP action.php 에서 입력한 암호와 게시물의 암호가 같은 지 검사 action 값에 따라 수정과 삭제 페이지로 이동 변수 처리 • $action = $_POST["action"]; • $id = $_POST["id"]; • $start = $_POST["start"]; 암호 검사 부분 • 기존 암호 가져오기 • $sql = "SELECT userpwd FROM gbook WHERE gb_id = " . $id; • $result = mysql_query($sql); • $isHere = mysql_num_rows($result); • if($isHere) { $storedPwd = mysql_result($result, 0, 0); 한림대학교 웹데이터베이스 - 이윤환
  • 7. VALIDATE_USER.PHP • 입력 암호의 암호화 • $sql = "SELECT password('" . trim($_POST["getPWD"]) . "');"; • $result = mysql_query($sql); • $inputPwd = mysql_result($result, 0, 0); • 암호 비교 • if(strcmp($storedPwd, $inputPwd)) • strcmp 함수는 두 문자열을 비교하여 같으면 0 반환 페이지 이동 switch($action) { case 'update' : ?> // 이동을 위한 JavaScript <?php break; case 'delete' : ?> // 이동을 위한 JavaScript <?php break; } 한림대학교 웹데이터베이스 - 이윤환
  • 8. 글 수정 입력 변수와 점검 $action = $_GET["action"]; $id = $_GET["id"]; $start = $_GET["start"]; if(isset($_GET["action"]) AND isset($_GET["id"]) AND isset($_GET["start"])) { 기존 내용 가져오기 $sql = "SELECT gb_id, writer, comments FROM gbook WHERE gb_id=" . $id; $result = mysql_query($sql); $rows = mysql_fetch_array($result, MYSQL_ASSOC); 한림대학교 웹데이터베이스 - 이윤환
  • 9. 글 수정 기본값 설정 <input id="getID" name="getID" type="text" size="20" maxlength="20" value="<?php echo $rows["writer"];?>" /> … <textarea id="getComments" name="getComments" rows="10" cols="40"><?php echo $rows["comments"];?></textarea> hidden을 통한 값 전달 <input type="hidden" name="id" value="<?php echo $id;?>" /> <input type="hidden" name="start" value="<?php echo $start;?>" /> 한림대학교 웹데이터베이스 - 이윤환
  • 10. 글 수정 처리 폼 값 검정(Form Validation) – 글쓰기와 동일 수정을 위한 SQL – UPDATE $sql = "UPDATE gbook SET writer='" . $getID . "', comments='" . $getComments . "', userPwd=password('" . $getPWD . "') WHERE gb_id = " . $_POST["id"]; 돌아가기 echo "<script type="text/javascript">n"; echo " location.href='list.php?start=" . $_POST["start"] . "';n"; echo "</script>n"; exit; 한림대학교 웹데이터베이스 - 이윤환
  • 11. 글 삭제 삭제 여부 재확인 <script type="text/javascript"> var isDel = confirm("정말로 삭제하시겠습니까?"); if(!isDel) { location.href='list.php?start=' + '<?php echo $start;?>'; } </script> 삭제를 위한 SQL – DELETE $sql = "DELETE FROM gbook WHERE gb_id = " . $id; 돌아가기 <script type="text/javascript"> alert("삭제하였습니다."); location.href='list.php?start=' + '<?php echo $start;?>'; </script> 한림대학교 웹데이터베이스 - 이윤환
  • 12. 수고하셨습니다. PHP 를 사용하는 방법에 대해 한학기간 살펴봤습니 다. 기말과제는 로그인한 사용자만 글쓰기가 가능하고 그렇지 않은 사용자는 읽을 수 있는 방명록을 만드 시면 됩니다. http://openx3.tistory.com 이나 페이스북 페이 지 “Web 개발해 봅시다 – 한림대학교”를 통해 궁 금한 것 있으면 언제든 연락주시기 바랍니다. 한림대학교 웹데이터베이스 - 이윤환