Add: add_player

This commit is contained in:
2018-07-02 09:41:49 +09:00
parent 6c5eb43bb9
commit dc638a8e1b
4 changed files with 222 additions and 37 deletions
+7 -1
View File
@@ -25,7 +25,13 @@ $result = mysqli_query($db_conn, $query);
function send_error_message($replyJSON, $error_message) {
$replyJSON["ERROR"] = $error_message;
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
// $db_conn->close();
}
function send_result_message($replyJSON, $result_message) {
$replyJSON["RESULT"] = $result_message;
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
// $db_conn->close();
}
?>
+72
View File
@@ -0,0 +1,72 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
$playerName = $_POST["player_name"];
$enterCode = $_POST["enter_code"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "./../setup/connect_db.php";
function send_error_message2($replyJSON, $error_message) {
$replyJSON["ERROR"] = $error_message;
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
// $db_conn->close();
}
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result !== null) {
send_error_message2($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
// $db_conn->close();
exit;
}
addPlayer($maestroID, $playerName, $enterCode);
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result === null) {
send_result_message($replyJSON, "fail");
exit;
} else {
send_result_message($replyJSON, "success");
exit;
}
// echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
// $db_conn->close();
function hasPlayerName($maestroID, $playerName, $enterCode) {
global $db_conn;
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($userID);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
// $replyJSON["UserID"] = $userID;
return $userID;
}
function addPlayer($maestroID, $playerName, $enterCode) {
global $db_conn;
$query = "INSERT INTO moty_user (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
$stmt->execute();
}
?>
+13 -13
View File
@@ -1,7 +1,7 @@
<?php
header('Content-Type: application/json');
$maestro_name = $_POST["maestro_name"];
$maestroName = $_POST["maestro_name"];
$name = $_POST["name"];
$enterCode = $_POST["enter_code"];
/*
@@ -16,15 +16,15 @@ if(!is_numeric($enterCode)) {
include "./../setup/connect_db.php";
$maestro_id = get_maestro_id($maestro_name);
if($maestro_id == null) {
$maestroID = get_maestro_id($maestroName);
if($maestroID === null) {
send_error_message($replyJSON, "입력한 마에스트로 계정이 없습니다");
$db_conn->close();
exit;
}
$replyJSON = get_login_data($maestro_id, $name, $enterCode);
if($replyJSON["UserID"] == null) {
$replyJSON = get_login_data($maestroID, $name, $enterCode);
if($replyJSON["UserID"] === null) {
send_error_message($replyJSON, "입력한 이름/입장번호와 일치하는 계정이 없습니다");
$db_conn->close();
exit;
@@ -34,36 +34,36 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function get_maestro_id($maestro_name) {
function get_maestro_id($maestroName) {
global $db_conn;
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $maestro_name);
$stmt->bind_param('s', $maestroName);
$stmt->execute();
$stmt->bind_result($maestro_id);
$stmt->bind_result($maestroID);
// while($stmt->fetch()) {
// ;
// }
$stmt->fetch();
$stmt->close();
return $maestro_id;
return $maestroID;
}
function get_login_data($maestro_id, $name, $enterCode) {
function get_login_data($maestroID, $name, $enterCode) {
global $db_conn;
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND enterCode=?";
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iss', $maestro_id, $name, $enterCode);
$stmt->bind_param('iss', $maestroID, $name, $enterCode);
$stmt->execute();
$stmt->bind_result($user_id);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
$replyJSON["MaestroID"] = $maestro_id;
$replyJSON["MaestroID"] = $maestroID;
$replyJSON["UserID"] = $user_id;
return $replyJSON;