로그인 후 '회원정보 수정'버튼 클릭

1
2
3
<a class="btn btn-outline-primary" href="/test/Board/write">글쓰기</a>
<a class="btn btn-outline-primary" href="/test/LogIn/logout">로그아웃</a>
<a class="btn btn-outline-primary" href="/test/UpdateAccount/InputPassword">회원정보 수정</a>
 

회원정보 수정을 하기위해 2차 본인 확인차 비번 입력 기능 추가

입력한 비번이 틀리면

입력한 비번이 맞으면 '회원 정보 수정' 페이지로 이동

[InputPassword.php]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
    session_start();    //session 가져오기
    //session에 데이터가 없다면 로그인 화면으로 GO
    if (!isset($_SESSION['userID'])) {
        header('Location : http://wamp서버ip주소:80/test/LogIn/login');
    }
?>
<!DOCTYPE html>
<html>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="/test/js/bootstrap.js"></script>
    <head>
        <meta charset = "utf=8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>본인 확인</title>
        <link rel ="stylesheet" href="/test/css/bootstrap.css">
        <link rel="stylesheet" href="/test/css/login.css">
        <link href="https://fonts.googleapis.com/css?family=Nanum+Brush+Script" rel="stylesheet">
    </head>
    <style>
    #check_password{
        font-size: 1.3em;
        width: 50%;
        display: inline-block;
    }
    </style>
    <script>
    $(document).ready(function(){
        $('#check_password').submit(function(e){
            e.preventDefault();
            if($('#PWD').val()==""){
                alert("비밀번호를 입력해 주세요.")
            }else{
                $.ajax({
                    type : 'POST',
                    url : 'http://wamp서버ip주소:80/test/UpdateAccount/CheckPassword',
                    data : $('#check_password').serialize(),
                    success : function(result){
                        if(result=="success"){
                            location.replace('http://wamp서버ip주소:80/test/UpdateAccount/update_account')
                        }else if(result=="Fail:Password"){
                            alert("해당 비밀번호가 틀렸습니다.");
                        }else if(result=="Fail:No Data"){
                            alert("비밀번호가 틀렸습니다. 다시 시도해 주세요.");
                        }
                    },
                    error : function(xtr,status,error){
                        alert(xtr +":"+status+":"+error);
                    }
                });
            }
        });
    });
    </script>
    <body>
        <div id="loginer">
            <form id = "check_password" method="POST">
                <fieldset>
                    <legend>Ckeck Your Password</legend>
                    PASSWORD : <input type="text" id ="PWD" name ="PWD" placeholder="Enter Your Password">
                    <br><br>
                    <input type="submit" value="본인 확인!">
                    <br>
                </fieldset>
            </form>
        </div>
    </body>
</html>
 
 

[CheckPassword.php]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
    include "../connect_db.php";
 
    session_start();    //session 가져오기
    //session에 데이터가 없다면 로그인 화면으로 GO
    if (!isset($_SESSION['userID'])) {
        header('Location : http://wamp서버ip주소:80/test/LogIn/login');
    }
    
    $pass = $_POST['PWD'];
 
    $id = $_SESSION['userID'];
    $name = $_SESSION['userNAME'];
 
    $sql = "SELECT userPWD FROM member WHERE userID ='$id' AND userPWD = '$pass'";
    $result = $db->query($sql);
 
    if($result->num_rows==1){
        $row=$result->fetch_array(MYSQLI_ASSOC);
        if($pass == $row['userPWD']){
            echo "success";
        }
    }else{
        echo "Fail:No Data";
    }
?>
 
 

비밀 번호 또는 전화 번호만 입력하면 입력하지 않은 정보를 입력하고 출력

비번과 전화번호를 둘다 입력 하고 변경 버튼을 누르면 성공 메시지 출력

smith@naver.com에서 smith111로

010-1111-1111에서 111-1111-1111로 바뀌었다.

[update_account.php]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
    session_start();    //session 가져오기
    //session에 데이터가 없다면 로그인 화면으로 GO
    if (!isset($_SESSION['userID'])) {
        header('Location : http://wamp서버ip주소:80/test/LogIn/login');
    }
?>
<!DOCTYPE html>
<html>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="/test/js/bootstrap.js"></script>
    <head>
        <meta charset = "utf=8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>회원 정보 수정</title>
        <link rel ="stylesheet" href="/test/css/bootstrap.css">
        <link rel="stylesheet" href="/test/css/login.css">
        <link href="https://fonts.googleapis.com/css?family=Nanum+Brush+Script" rel="stylesheet">
    </head>
    <style>
    #update_form{
        font-size: 1.3em;
        width: 50%;
        display: inline-block;
    }
    </style>
    <script>
    $(document).ready(function(){
        $('#update_form').submit(function(e){
            e.preventDefault();
            if($('#PWD').val()==""){
                alert("비밀번호를 입력해 주세요.");
            }else if($('#phone').val()==""){
                alert("전화번호를 입력해 주세요.");
            }else{
                $.ajax({
                    type : 'POST',
                    url : 'http://wamp서버ip주소:80/test/UpdateAccount/update',
                    data : $('#update_form').serialize(),
                    success : function(result){
                        if(result=="success"){
                            alert("성공적으로 변경하였습니다.");
                            location.replace('http://wamp서버ip주소:80/test/main')
                        }else if(result=="Fail:Save"){
                            alert("변경 실패 다시 시도해주세요.");
                        }
                    },
                    error : function(xtr,status,error){
                        alert(xtr +":"+status+":"+error);
                    }
                });
            }
        });
    });
    </script>
    <body>
        <div id="loginer">
            <form id = "update_form" method="POST">
                <fieldset>
                    <legend>회원 정보 수정</legend>
                    비밀번호 : <input type="text" id ="PWD" name ="PWD" placeholder="Enter Your Password">
                    <br><br>
                    전화번호 : <input type="text" id ="phone" name ="phone" placeholder="Enter Your phone">
                    <br><br>
                    <input type="submit" value="변경!">
                    <br>
                </fieldset>
            </form>
        </div>
    </body>
</html>
 
 

 

[update.php]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
    include "../connect_db.php";
 
    session_start();    //session 가져오기
    //session에 데이터가 없다면 로그인 화면으로 GO
    if (!isset($_SESSION['userID'])) {
        header('Location : http://wamp서버ip주소:80/test/LogIn/login');
    }
    
    $pwd = $_POST['PWD'];
    $phone = $_POST['phone'];
 
    $id = $_SESSION['userID'];
 
    $sql = "UPDATE member SET userPWD ='$pwd' , userPHONE ='$phone' WHERE userID='$id'";
 
    $result = $db->query($sql);
 
    if($result){
        echo "success";
    }else{
        echo "Fail:Save";
    }
?>
 
 

+ Recent posts