본문 바로가기
IT/PHP

php 회원가입 4-3

by Jeami 2013. 8. 22.
반응형



join.php

join_form.php 에서 submut 으로 지정된 SAVE 버튼을 클릭하면 실행되는 페이지입니다. 회원가입 정보를 DB에 저장하는 쿼리문을 만들어두는 페이지인데요.

DB 쿼리문 외에 입력칸이 비어있을 경우 DB가 저장되지 않도록 하는 명령문까지 추가해주어야 합니다.

lib.php 파일에 에러처크 하기위한 Error() 함수를 만들두었기 때문에 아래와 같이 if()문만 작성해주면 되겠습니다. ==> 입력칸이 비어있을 경우 DB에 저장되지 않아야 하기 때문에 DB쿼리문 이전에 if문을 삽입해두어야 하는 것을 잊지마세요^^

<?php

   include "config_inc.php";
   include "lib.php";
   $conn = dbconn();

       if( !$name ) Error(' NAME area emptied, please enter info');
       if( !$id ) Error(' ID area emptied, please enter info');
       if( !$passwd ) Error(' PASSWORD area emptied, please enter info');
       if( !$email ) Error(' E_Mail area emptied, please enter info');
   
   $wdate = time();
   $grade = 9;
   $query = "insert into bbs_member(user_id, name, passwd, email, wdate, ip, grade)
                    values('$user_id', '$name', '$passwd', '$email', '$wdate', '$ip', '$grade')";
   mysql_query($query,$conn);
?>
<script type="text/javascript">
    location.href = 'list.php?id=<?=$id?>';
</script>


(실제 FORM 은 다릅니다.)



join_form.php


<?php
   include "config_inc.php";
   include "lib.php";
   $conn = dbconn();
   $set = set();
?>
<script>
    function id_chk(){
         if(!document.join.user_id.value){   
            alert("can't empty this area!!");
            document.join.user_id.focus();
            return false;     
        }
        // 팝업창 window.open('파일명:id값을 넘겨줌','창타이틀','창폼');
        var uid = document.join.user_id.value;
        document.join.passwd.focus();
        window.open( 'id_chk.php?user_id='+uid , '' , 'width=400, height=130' );
    }//end


// 각 입력창의 문자갯수를 확인해서 그 이하 및 이상일 경우 재입력하도록 유도합니다. 문자열 길이는 lengh 를 이용해주시면 됩니다. 중요한 것은 return false 인데요. 반드시 false 값을 리턴해주어야만 합니다. 에러 메시지를 띄운 후에는 해당 입력칸(id 혹은 password)으로 이동할 수 있도록 해주었습니다.


    function param_check(){
        if( join.user_id.value.length < 10 ){
            alert(" ID is between 6 and 8 words");
            join.user_id.focus();
            return false;   
        }
        if( join.user_id.value.length >= 21 ){
            alert(" ID is between 6 and 8 words");
            join.user_id.focus();
            return false;   
        }
        if( join.passwd.value.length < 6 ){
            alert(" PASSWORD is between 6 and 8 words");
            join.passwd.focus();
            return false;   
        }
        if( join.passwd.value.length >= 16 ){
            alert(" PASSWORD is between 6 and 8 words");
            join.passwd.focus();
            return false;   
        }
        if( join.passwd.value != document.join.confirm.value ){
            alert("Password and PasswordConfirm is different!!");
            join.confirm.focus();
            return false;   
        }
    }
       
   
</script>
<link rel=StyleSheet HREF=style.css type=text/css>
<form action=join.php name=join method="post" onsubmit="return param_check()">
<div align="center">
<input type=hidden name=id value='<?=$id?>'>
<table width=600 border=0 cellpadding=1 cellspacing=1 bgcolor=#999999>
    <tr >
        <td
            <table width=100% >
            <tr >
                <td colspan=2 align="center" height=20><b>JOIN FORM</b>
            <tr>
               <td colspan=2 height=1>       
            <tr>   
                <td align="right">NAME
                <td>&nbsp;&nbsp;&nbsp;<input type=text name=name size=20>              
            <tr>
                <td align="right">I.D
                <td>&nbsp;&nbsp;&nbsp;<input type=text name=user_id size=20>
                        &nbsp;&nbsp;<input type=button value=IDcheck onclick="id_chk()"><!-- id_chk() 함수로 이동 -->
                        <font color=gray>*limited words under 10~20 </font>
            <tr>   
                <td align="right">PASSWORD
                <td>&nbsp;&nbsp;&nbsp;<input type=password name=passwd size=20>
                        <font color=gray>*limited words under 6~15 use Eng/Num </font>
               
            <tr>   
                <td align="right">PASSWARD CHECK
                <td>&nbsp;&nbsp;&nbsp;<input type=password name=confirm size=20>               
            <tr>   
                <td align="right">E_MAIL
                <td>&nbsp;&nbsp;&nbsp;<input type=text name=email size=30>       
            <tr>
                <td colspan=2 align="center" height=30 valign="bottom"><input type=submit value=SAVE>
            </table>
        </td>
    </tr>               
</table>
</div>
</form>




반응형

'IT > PHP' 카테고리의 다른 글

php foreach as 루프  (0) 2013.08.23
php 회원가입 4-4  (0) 2013.08.22
php 회원가입 4-2  (0) 2013.08.22
php 회원가입 4-1  (0) 2013.08.22
php 페이징  (0) 2013.08.21

loading