React Native

react native php-> myqli 연동

Machine_웅 2020. 1. 21. 13:50
728x90
반응형

Rn

 // 서버와의 통신 
    // mode == 1 아이디 체크   mode == 2 닉네임체크 
    fetchData = async(mode,data) =>{
        console.log("fetch 시도 ")
        fetch("http://192.168.0.224:80/eo1Project/Account/checkExistData.php",{

            method: 'POST',
            headers: {
              'Accept': 'application/json',
              'Content-Type': 'application/json',
            },
            body: JSON.stringify({
              userData: data,
              mode:mode
            })

        })
        .then((response)=> response.json())
        .then((responseJson) => {
            console.log('response:', responseJson)
            if(responseJson.result == 0){
                alert('사용 가능')
            }else{

                if(mode == 1){
                    alert('이미 사용중인 아이디 입니다.')

                    this.setState({
                        userEmail : "",
                        userEmailCheck : false
                    })
                }else{

                    alert('이미 사용중인 닉네임 입니다.')

                    this.setState({
                        userNick : "",
                        userNickCheck : false
                    })
                }
            }
         }
        )
        .done()
        // .then((res) =>{
        //     alert(res)
        // })
        // 제이슨 형태로 반환 한다. ( PHP=> RN 으로 올때 Json 형식으로 보낸다 . )
      }

 

php

 

<?php

    header('Content-Type: text/html; charset=UTF-8');
    header('Content-Type: application/json');
    header("Content-Type:text/html;charset=utf-8");

    $json = json_decode(file_get_contents('php://input'), true);

    $userData = $json['userData'];
    $mode = $json['mode'];


    if($mode == 1){

        $conn = mysqli_connect('localhost','root', '', 'intro_company');
        $setQuary = "SELECT * FROM user_data WHERE loginUserId ='$userData'";
        $search = mysqli_query($conn,$setQuary);
        $total_rows = mysqli_num_rows($search);

        echo json_encode(array(
            'result' => $total_rows,
        ))

        
    }else{
        
        $conn = mysqli_connect('localhost','root', '', 'intro_company');
        $setQuary = "SELECT * FROM user_data WHERE loginUserNick ='$userData'";
        $search = mysqli_query($conn,$setQuary);
        $total_rows = mysqli_num_rows($search);

        echo json_encode(array(
            'result' => $total_rows,
        ))

    }

  




    //값 가지고 오기 
    // while($row = mysqli_fetch_array($search)) {

    //     if($row['loginUserId'] == $userEmail ){
    //         $result = "있음";
    //     }

    // }

  

?>


 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형

'React Native' 카테고리의 다른 글

React Native 비동기 처리 async / await  (0) 2020.01.22
React native Async Storage  (0) 2020.01.21
React Native FlatList 추가  (0) 2020.01.17
React Native ToastAndroid  (0) 2020.01.17
React native ViewPager 사용하기  (0) 2020.01.17