본문 바로가기
웹 개발

[PHP] 회원가입에서 아이디 중복 체크

by hans-0 2025. 2. 24.

아이디 중복 체크

<?php
$fuserid = isset($_GET['fuserid']) ? $_GET['fuserid'] : '';

// 데이터베이스 연결
include "./connect_db.php";

// SQL 인젝션 방지 처리
$fuserid = mysqli_real_escape_string($connect, $fuserid);

// 아이디 중복 검사 SQL 실행
$sql = "SELECT COUNT(*) FROM user_tbl WHERE userid='$fuserid'";
$res = mysqli_query($connect, $sql);
$rs = mysqli_fetch_array($res);
$num = $rs[0];

// DB 연결 종료
mysqli_close($connect);
?>

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>아이디 중복 검사</title>
    
    <style>
        /* 기본 스타일 */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f8f9fa;
            text-align: center;
            margin: 50px;
        }

        /* 테이블 스타일 */
        table {
            width: 350px;
            border-collapse: collapse;
            margin: auto;
            background-color: white;
            border: 1px solid green;
        }

        td {
            padding: 10px;
            text-align: center;
        }

        /* 제목 스타일 */
        .header {
            background-color: #3300CC;
            color: white;
            font-weight: bold;
        }

        /* 버튼 스타일 */
        .btn {
            padding: 10px 15px;
            border: none;
            color: white;
            background-color: #28a745;
            border-radius: 5px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
        }

        .btn:hover {
            background-color: #218838;
        }
    </style>
</head>
<body>

    <form name="chkid_form">
        <table>
            <tr class="header">
                <td>아이디 중복 검사</td>
            </tr>
            <tr height="120">
                <td>
                    <?php if ($num > 0) { ?>
                        <p><strong>[ <?php echo htmlspecialchars($fuserid); ?> ]</strong> 는 사용 중인 아이디입니다.</p>
                        <p>다른 아이디를 선택하세요.</p>
                    <?php } else { ?>
                        <p><strong>[ <?php echo htmlspecialchars($fuserid); ?> ]</strong> 는 사용 가능합니다.</p>
                    <?php } ?>
                    <br>
                    <input type="button" class="btn" value=" 닫기 " onClick="self.close();">
                </td>
            </tr>
        </table>
    </form>

</body>
</html>

 

 

참고 서적 > PHP Promgramming 정복하기

https://www.yes24.com/Product/Goods/19584929

 

PHP Programming 정복하기 - 예스24

웹 데이터베이스 프로그래밍에 대한 공부를 하겠다는 의지로 막상 뛰어 들었지만 항상 난관에 부딪치는 경험은 누구나 한 번쯤 겪었으리라 생각됩니다. 웹 데이터베이스는 구축하기 위해서는

www.yes24.com

이 코드는 책 "PHP 프로그래밍 정복"의 내용을 참고하여, 최신 PHP 버전에 맞게 수정하였습니다.

 

이전 글 

2025.02.24 - [웹 개발] - [PHP] 회원 가입 페이지

'웹 개발' 카테고리의 다른 글

[PHP] 회원 가입 페이지  (0) 2025.02.24
[PHP] 회원 관리 프로그램 제작 성공 화면  (0) 2025.02.19
[PHP] 관리자 페이지 제작 & DB 접속  (0) 2025.02.13
[APM] Ubuntu 22.04 APM 설치  (0) 2025.02.10
Cookie & Session  (0) 2025.01.23