웹마스터 팁

modify_ok.php3 파일
1 <?
      2   include "lib.php3";
      3   include "dbconn.php3";
      4
      5   // 암호, 이름, 내용에 대해서 입력을 하지 않았을 경우 에러메세지 출력
      6   if(isBlank($password)) message("암호를 입력하셔야 합니다");
      7   if(isBlank($writer)) message("이름을 입력하셔야 합니다");
      8   if(isBlank($comment)) message("내용을 입력하셔야 합니다");
      9
     10   // 글쓴이의 비밀 번호를 DB 로 부터 가져와서 비교, 관리자 비번일때는 수정 가능
     11   $result=mysql_query("select password from $table_name where no='$no'", $connect);
     12   $check_passwd=mysql_fetch_array($result);
     13
     14   if($check_passwd["password"]!=$password && $admin_password!=$password) message("비밀번호가 틀렸습니다");
     15
     16
     17   // 홈페이지 주소의 경우 http:// 가 없으면 붙임
     18   if((!eregi("^http://",$homepage))&&$homepage) $homepage="http://".$homepage;
     19
     20   // 이름, 홈페이지, 메일, 본문내용 중 '등의 특수문자 존재시 앞에 (역슬래쉬)를 붙여줌
     21   $writer=addslashes($writer);
     22   $homepage=addslashes($homepage);
     23   $email=addslashes($email);
     24   $comment=addslashes($comment);
     25
     26   // 방명록 내용등에 html 태그등을 잘못 써서 화면이 깨지는 것 방지
     27   $writer=avoid_crack($writer);
     28   $email=avoid_crack($email);
     29   $comment=avoid_crack($comment);
     30
     31   // html 사용하지 않을시 del_html() 함수로 태그를 일반문자로 변환
     32   if(!$use_html) $comment=del_html($comment);
     33
     34   // 방명록의 본문 내용의 n(줄바꿈)을 <br> 태그로 변환
     35   $comment=nl2br($comment);
     36
     37   // 현재 접속자의 IP주소 체크
     38   $ip=$REMOTE_ADDR;
     39
     40   // 지금 글쓴 시간을 체크
     41   $reg_date=time();
     42
     43   // DB에 입력
     44   mysql_query("update $table_name set
     45                ip='$ip',
     46                writer='$writer',
     47                homepage='$homepage',
     48                email='$email',
     49                comment='$comment',
     50                reg_date='$reg_date'
     51                where no='$no'", $connect)
     52   or die(mysql_error());
     53
     54   header("location:list.php3");
     55 ?>

내용설명

수정시에는 비밀번호를 검사하는 루틴을 추가하여야 합니다.
글쓴이가 입력한 비밀번호와 관리자비밀번호를 MySQL DB에 저장되어 있는 비밀번호와 비교하여 둘중의 하나와 같다면 수정하고 그렇지 않다면 경고메세지를 출력합니다.

11~12 : MySQL DB에서 $no 행의 데이터중 비밀번호를 가져옵니다.

14 : 입력된 비밀번호와 관리자 비밀번호를 MySQL DB에서 구한 비밀번호와 비교하여 틀리면 경고메세지를 출력합니다.

44~52 : update 쿼리를 사용하여 데이터를 수정합니다.