프로그래밍/안드로이드

안드로이드 - 3. 수강신청앱 회원 데이터베이스 구축

가카리 2018. 5. 7. 00:48
반응형


CREATE DATABASE `registration` CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE USER(
userID VARCHAR(50) NOT NULL,
userPassword VARCHAR(50) NOT NULL,
userGender VARCHAR(50) NOT NULL,
userMajor VARCHAR(50) NOT NULL,
userEmail VARCHAR(50) NOT NULL,
CONSTRAINT PRIMARY KEY(userID)
);

UserRegister.php

<?php
    $con = mysqli_connect('localhost', 'root', '1234', 'registration');
     //안드로이드 앱으로부터 아래 값들을 받음
     $userID = $_POST['userID'];
     $userPassword = $_POST['userPassword'];
     $userGender =  $_POST['userGender'];
     $userMajor = $_POST['userMajor'];
     $userEmail = $_POST['userEmail'];
     //insert 쿼리문을 실행함
     $statement = mysqli_prepare($con, "INSERT INTO USER VALUES (?, ?, ?, ?, ?)");
     mysqli_stmt_bind_param($statement, "sssss", $userID, $userPassword, $userGender, $userMajor, $userEmail);
     mysqli_stmt_execute($statement);
     $response = array();
     $response["success"] = true;
     //회원 가입 성공을 알려주기 위한 부분임
     echo json_encode($response); 
?>


UserValidate.php

<?php
    $con = mysqli_connect('localhost', 'root', 'qwer1234', 'registration');
     $userID = $_POST['userID'];
     $statement = mysqli_prepare($con, "SELECT * FROM USER WHERE userID = ?");
     mysqli_stmt_bind_param($statement, "s", $userID);
     mysqli_stmt_execute($statement);
     mysqli_stmt_store_result($statement);
     mysqli_stmt_bind_result($statement, $userID);
     $response = array();
     $response["success"] = true;
     while(mysqli_stmt_fetch($statement)){
       $response["success"] = false;//회원가입불가를 나타냄
       $response["userID"] = $userID;
     }
     //데이터베이스 작업이 성공 혹은 실패한것을 알려줌
     echo json_encode($response);
?>


AndroidManifest.xml

인터넷을 사용하기 위해  INTERNET 퍼미션을 추가해줍니다.

<?xml version="1.0" encoding="utf-8"?>
    package="com.example.kch.registration_v3">

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">
        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity"></activity>
    </application>

</manifest>


그다음 왼쪽 Gradle Scripts에 build.gradle(Module: app) 에

 Volley 라이브 사용을 위해 아래와 같이 추가해줍니다.







반응형