diff --git a/barobill_registration/api.php b/barobill_registration/api.php index 90aa0fe..960efd8 100644 --- a/barobill_registration/api.php +++ b/barobill_registration/api.php @@ -3,24 +3,34 @@ header('Content-Type: application/json'); require_once("../lib/mydb.php"); $method = $_SERVER['REQUEST_METHOD']; -$pdo = db_connect(); +try { + $pdo = db_connect(); -switch ($method) { - case 'GET': - handleGet($pdo); - break; - case 'POST': - handlePost($pdo); - break; - case 'PUT': - handlePut($pdo); - break; - case 'DELETE': - handleDelete($pdo); - break; - default: - echo json_encode(['error' => 'Method not allowed']); - break; + switch ($method) { + case 'GET': + handleGet($pdo); + break; + case 'POST': + handlePost($pdo); + break; + case 'PUT': + handlePut($pdo); + break; + case 'DELETE': + handleDelete($pdo); + break; + default: + http_response_code(405); + echo json_encode(['error' => 'Method not allowed']); + break; + } +} catch (Exception $e) { + http_response_code(500); + echo json_encode([ + 'error' => 'Backend Error', + 'message' => $e->getMessage(), + 'hint' => 'Check if the database table exists by running init_db.php' + ]); } function handleGet($pdo) { @@ -122,4 +132,3 @@ function handleDelete($pdo) { echo json_encode(['error' => $e->getMessage()]); } } -?> diff --git a/barobill_registration/index.php b/barobill_registration/index.php index 17e522a..9c52fb5 100644 --- a/barobill_registration/index.php +++ b/barobill_registration/index.php @@ -25,10 +25,18 @@ } - - - + + + + + + + +
@@ -187,14 +195,30 @@ const [loading, setLoading] = useState(true); const [activeTab, setActiveTab] = useState('list'); const [editingMember, setEditingMember] = useState(null); + + // Auto-fill feature states + const [registerKey, setRegisterKey] = useState(0); + const [initialTestData, setInitialTestData] = useState({}); const fetchMembers = async () => { setLoading(true); try { const res = await fetch('api.php'); - const data = await res.json(); - setMembers(data.members || []); - } catch (e) { console.error(e); } + const text = await res.text(); + try { + const data = JSON.parse(text); + if (data.error) { + alert(`서버 오류: ${data.message || data.error}\n${data.hint || ''}`); + } + setMembers(data.members || []); + } catch (parseError) { + console.error("Invalid JSON response:", text); + alert("서버로부터 올바르지 않은 응답이 수신되었습니다. DB 연결 또는 테이블 생성 여부를 확인해주세요."); + } + } catch (e) { + console.error(e); + alert("통신 오류가 발생했습니다."); + } setLoading(false); }; @@ -319,12 +343,44 @@ ) : (입력된 정보로 바로빌 RegistCorp API가 호출됩니다.
+입력된 정보로 바로빌 RegistCorp API가 호출됩니다.
+