회원가입
2022. 2. 16. 10:32ㆍStudy/PHP&MySQL
/member/member.sql
create table member (
id char(15) not null,
pass char(41) not null,
name char(10) not null,
nick char(10) not null,
hp char(20) not null,
email char(80),
regist_day char(20),
level int,
primary key(id)
);
/member/member_form.php
<form> 데이터 전송방식
name="member_form" | method="post" | action="insert.php" |
insert.php에 넘겨줄 데이터
아이디 | $id |
비밀번호 | $pass |
비밀번호 확인 | $pass_confirm |
이름 | $name |
닉네임 | $nick |
휴대폰 | $hp1 $hp2 $hp3 |
이메일 | $email1 $email2 |
<?
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="../css/common.css" rel="stylesheet" media="all">
<link href="../css/member.css" rel="stylesheet" media="all">
<script>
function check_id()
{
window.open("check_id.php?id=" + document.member_form.id.value,
"IDcheck",
"left=200,top=200,width=200,height=60,scrollbars=no,resizable=yes");
}
function check_nick()
{
window.open("check_nick.php?nick=" + document.member_form.nick.value,
"NICKcheck",
"left=200,top=200,width=200,height=60,scrollbars=no,resizable=yes");
}
function check_input()
{
if (!document.member_form.id.value)
{
alert("아이디를 입력하세요");
document.member_form.id.focus();
return;
}
if (!document.member_form.pass.value)
{
alert("비밀번호를 입력하세요");
document.member_form.pass.focus();
return;
}
if (!document.member_form.pass_confirm.value)
{
alert("비밀번호확인을 입력하세요");
document.member_form.pass_confirm.focus();
return;
}
if (!document.member_form.name.value)
{
alert("이름을 입력하세요");
document.member_form.name.focus();
return;
}
if (!document.member_form.nick.value)
{
alert("닉네임을 입력하세요");
document.member_form.nick.focus();
return;
}
if (!document.member_form.hp2.value || !document.member_form.hp3.value )
{
alert("휴대폰 번호를 입력하세요");
document.member_form.nick.focus();
return;
}
if (document.member_form.pass.value !=
document.member_form.pass_confirm.value)
{
alert("비밀번호가 일치하지 않습니다.\n다시 입력해주세요.");
document.member_form.pass.focus();
document.member_form.pass.select();
return;
}
document.member_form.submit();
}
function reset_form()
{
document.member_form.id.value = "";
document.member_form.pass.value = "";
document.member_form.pass_confirm.value = "";
document.member_form.name.value = "";
document.member_form.nick.value = "";
document.member_form.hp1.value = "010";
document.member_form.hp2.value = "";
document.member_form.hp3.value = "";
document.member_form.email1.value = "";
document.member_form.email2.value = "";
document.member_form.id.focus();
return;
}
</script>
</head>
<body>
<div id="wrap">
<div id="header"><? include "../lib/top_login2.php"; ?></div> <!-- end of header -->
<div id="menu"><? include "../lib/top_menu2.php"; ?></div> <!-- end of menu -->
<div id="content">
<div id="col1">
<div id="left_menu"><? include "../lib/left_menu.php"; ?></div>
</div> <!-- end of col1 -->
<div id="col2">
<form name="member_form" method="post" action="insert.php">
<div id="title"><img src="../img/title_join.gif"></div>
<div id="form_join">
<div id="join1">
<ul>
<li>* 아이디</li>
<li>* 비밀번호</li>
<li>* 비밀번호 확인</li>
<li>* 이름</li>
<li>* 닉네임</li>
<li>* 휴대폰</li>
<li> 이메일</li>
</ul>
</div>
<div id="join2">
<ul>
<li>
<div id="id1"><input type="text" name="id"></div>
<div id="id2"><a href="#"><img src="../img/check_id.gif" onclick="check_id()"></a></div>
<div id="id3">4~12자의 영문 소문자, 숫자와 특수기호(_) 만 사용할 수 있습니다.</div>
</li>
<li><input type="password" name="pass"></li>
<li><input type="password" name="pass_confirm"></li>
<li><input type="text" name="name"></li>
<li>
<div id="nick1"><input type="text" name="nick"></div>
<div id="nick2" ><a href="#"><img src="../img/check_id.gif" onclick="check_nick()"></a></div>
</li>
<li>
<select class="hp" name="hp1">
<option value='010'>010</option>
<option value='011'>011</option>
<option value='016'>016</option>
<option value='017'>017</option>
<option value='018'>018</option>
<option value='019'>019</option>
</select> -
<input type="text" class="hp" name="hp2"> -
<input type="text" class="hp" name="hp3">
</li>
<li><input type="text" id="email1" name="email1"> @ <input type="text" name="email2"></li>
</ul>
</div>
<div class="clear"></div>
<div id="must"> * 는 필수 입력항목입니다.^^</div>
</div>
<div id="button">
<a href="#"><img src="../img/button_save.gif" onclick="check_input()"></a>
<a href="#"><img src="../img/button_reset.gif" onclick="reset_form()"></a>
</div>
</form>
</div> <!-- end of col2 -->
</div> <!-- end of content -->
</div> <!-- end of wrap -->
</body>
</html>
/member/insert.php
member_form.php에서 받은 데이터를 정리(?)하여 포멧을 맞춘 후 mysql에 저장
<meta charset="utf-8">
<?
@extract($_GET);
@extract($_POST);
@extract($_SESSION);
/*
$id
$pass $pass_confirm
$name
$nick
$hp1 $hp2 $hp3
$email1 $email2
*/
$hp = $hp1."-".$hp2."-".$hp3; // 000-0000-0000
$email = $email1."@".$email2; // bini@nate.com
$regist_day = date("Y-m-d (H:i)"); // 현재의 '년-월-일-시-분'을 저장
$ip = $REMOTE_ADDR; // 방문자의 IP 주소를 저장
include "../lib/dbconn.php"; // dconn.php 파일을 불러옴
// id중복검사를 한번 더 한다.
$sql = "select * from member where id='$id'";
$result = mysql_query($sql, $connect);
$exist_id = mysql_num_rows($result);
if($exist_id) {
echo("
<script>
window.alert('해당 아이디가 존재합니다.');
history.go(-1);
</script>
");
exit;
}
else
{ // 레코드 삽입 명령을 $sql에 입력
$sql = "insert into member(id, pass, name, nick, hp, email, regist_day, level) ";
$sql .= "values('$id', password('$pass'), '$name', '$nick', '$hp', '$email', '$regist_day', 9)";
//패스워드는 password 함수를 사용. 암호화해서 저장한다.
mysql_query($sql, $connect); // $sql 에 저장된 명령 실행
}
mysql_close(); // DB 연결 끊기
echo "
<script>
alert('회원가입을 축하합니다.');
location.href = '../index.php';
</script>
";
?>
/member/check_id.php
<meta charset="utf-8">
<?
@extract($_GET);
@extract($_POST);
@extract($_SESSION);
/*
$id="green"; (get)
*/
if(!$id) // id가 입력되지 않았다면
{
echo("아이디를 입력하세요.");
}
else
{
include "../lib/dbconn.php";
$sql = "select * from member where id='$id' ";
$result = mysql_query($sql, $connect);
$num_record = mysql_num_rows($result);
// if ($num_record) // 검색 레코드가 있으면
// {
// echo "<div><img src='../img/id_no.jpg' alt=' ' /></div>";
// }
// else
// {
// echo "<div><img src='../img/id_ok.jpg' alt=' ' /></div>";
// }
if ($num_record)
{
echo "아이디가 중복됩니다!<br>";
echo "다른 아이디를 사용하세요.<br>";
}
else
{
echo "사용가능한 아이디입니다.";
}
mysql_close();
}
?>
/member/check_nick.php
<meta charset="utf-8">
<?
@extract($_GET);
@extract($_POST);
@extract($_SESSION);
/*
$nick="길동이"; (get)
*/
if(!$nick)
{
echo("닉네임을 입력하세요.");
}
else
{
include "../lib/dbconn.php";
$sql = "select * from member where nick='$nick' ";
$result = mysql_query($sql, $connect);
$num_record = mysql_num_rows($result);
// if ($num_record)
// {
// echo "<div><img src='../img/nick_no.jpg' alt=' ' /></div>";
// }
// else
// {
// echo "<div><img src='../img/nick_ok.jpg' alt=' ' /></div>";
// }
if ($num_record)
{
echo "닉네임이 중복됩니다.<br>";
echo "다른 닉네임을 사용하세요.<br>";
}
else
{
echo "사용가능한 닉네임입니다.";
}
mysql_close();
}
?>
예제파일
'Study > PHP&MySQL' 카테고리의 다른 글
SSH 접속프로그램 PuTTY 사용법 (0) | 2022.02.17 |
---|---|
회원가입 - ajax (0) | 2022.02.16 |
MySQL file upload (0) | 2022.02.15 |
form 메일보내기 mail() (0) | 2022.02.15 |
세션 (Session) (0) | 2022.02.15 |