5) { echo ""; exit; } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo ""; exit; } $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $biz_no = isset($_POST['biz_no']) ? trim($_POST['biz_no']) : ''; $company_name = isset($_POST['company_name']) ? trim($_POST['company_name']) : ''; $representative = isset($_POST['representative']) ? trim($_POST['representative']) : ''; $open_date = isset($_POST['open_date']) ? trim($_POST['open_date']) : null; $address = isset($_POST['address']) ? trim($_POST['address']) : null; $type = isset($_POST['type']) ? trim($_POST['type']) : null; $item = isset($_POST['item']) ? trim($_POST['item']) : null; $issue_date = isset($_POST['issue_date']) ? trim($_POST['issue_date']) : null; // 필수 필드 검증 if ($id <= 0) { echo ""; exit; } if (empty($biz_no) || empty($company_name) || empty($representative)) { echo ""; exit; } // 사업자번호 정규화 (하이픈 제거) $biz_no_clean = preg_replace('/[^0-9]/', '', $biz_no); if (strlen($biz_no_clean) !== 10) { echo ""; exit; } // 사업자번호 체크섬 검증 function validateBusinessNumber($num) { if (strlen($num) !== 10) return false; $checksum = [1, 3, 7, 1, 3, 7, 1, 3, 5]; $sum = 0; for ($i = 0; $i < 9; $i++) { $sum += intval($num[$i]) * $checksum[$i]; } $sum += floor((intval($num[8]) * 5) / 10); $lastDigit = (10 - ($sum % 10)) % 10; return $lastDigit === intval($num[9]); } if (!validateBusinessNumber($biz_no_clean)) { echo ""; exit; } // 하이픈 추가된 형식으로 저장 $biz_no_formatted = substr($biz_no_clean, 0, 3) . '-' . substr($biz_no_clean, 3, 2) . '-' . substr($biz_no_clean, 5); // 날짜 형식 정규화 $open_date = !empty($open_date) ? $open_date : null; $issue_date = !empty($issue_date) ? $issue_date : null; // 빈 문자열을 NULL로 변환 $address = !empty($address) ? $address : null; $type = !empty($type) ? $type : null; $item = !empty($item) ? $item : null; try { $pdo = db_connect(); // 데이터 존재 확인 $check_sql = "SELECT id FROM biz_cert WHERE id = :id"; $check_stmt = $pdo->prepare($check_sql); $check_stmt->bindValue(':id', $id, PDO::PARAM_INT); $check_stmt->execute(); if (!$check_stmt->fetch()) { echo ""; exit; } // 업데이트 $sql = "UPDATE biz_cert SET biz_no = :biz_no, company_name = :company_name, representative = :representative, open_date = :open_date, address = :address, type = :type, item = :item, issue_date = :issue_date WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->bindValue(':biz_no', $biz_no_formatted, PDO::PARAM_STR); $stmt->bindValue(':company_name', $company_name, PDO::PARAM_STR); $stmt->bindValue(':representative', $representative, PDO::PARAM_STR); $stmt->bindValue(':open_date', $open_date, $open_date ? PDO::PARAM_STR : PDO::PARAM_NULL); $stmt->bindValue(':address', $address, $address ? PDO::PARAM_STR : PDO::PARAM_NULL); $stmt->bindValue(':type', $type, $type ? PDO::PARAM_STR : PDO::PARAM_NULL); $stmt->bindValue(':item', $item, $item ? PDO::PARAM_STR : PDO::PARAM_NULL); $stmt->bindValue(':issue_date', $issue_date, $issue_date ? PDO::PARAM_STR : PDO::PARAM_NULL); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); echo ""; } catch (Exception $e) { echo ""; }