HTML
메모
- form (URL생성기) 안에서는 input만 의미가 있다.
- join.php
<!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>회원가입</title> </head> <body> <div align="center"> <h1>회원가입</h1> <hr> <form action="doJoin.php"> <div> <span>아이디</span> <input type="text" name="userId" required> </div> <div> <span>비밀번호</span> <input type="password" name="userPw" required> </div> <div> <span>이름</span> <input type="text" name="name" required> </div> <div> <span>별명</span> <input type="text" name="nickname" required> </div> <div> <span>전화번호</span> <input type="tel" name="cellphone" required> </div> <div> <span>이메일</span> <input type="email" name="email" required> </div> <div> <input onclick="location.href='doJoin.php'" type="submit" value="회원가입"> </div> </form> </div> </body> </html>
- doJoin.php
<?php $dbConn = mysqli_connect("127.0.0.1", "park", "park123414", "php_blog_2021") or die("CONNECTION ERROR"); if (isset($_GET['userId']) == false) { echo "userId를 입력해주세요."; exit; } if (isset($_GET['userPw']) == false) { echo "userPw를 입력해주세요."; exit; } if (isset($_GET['name']) == false) { echo "name를 입력해주세요."; exit; } if (isset($_GET['nickname']) == false) { echo "nickname를 입력해주세요."; exit; } if (isset($_GET['cellphone']) == false) { echo "cellphone를 입력해주세요."; exit; } if (isset($_GET['email']) == false) { echo "email를 입력해주세요."; exit; } $userId = $_GET['userId']; $userPw = $_GET['userPw']; $name = $_GET['name']; $nickname = $_GET['nickname']; $cellphone = $_GET['cellphone']; $email = $_GET['email']; $sql = " INSERT INTO `member` SET regDate = NOW(), userId = '$userId', userPw = '$userPw', `name` = '$name', nickname = '$nickname', cellphone = '$cellphone', email = '$email'; "; $rs = mysqli_query($dbConn, $sql); if($rs) { ?> <script> alert('가입 되었습니다.'); location.replace("./login.php"); </script> <?php } else{ ?> <script> alert("fail"); </script> <?php } mysqli_close($dbConn); ?>
- login.php
<!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>로그인</title> </head> <body> <div align="center"> <h1>로그인</h1> <hr> <form action="doLogin.php"> <div> <span>아이디</span> <input type="text" name="userId" required> </div> <div> <span>비밀번호</span> <input type="password" name="userPw" required> </div> <div> <input type="submit" value="로그인"> <input onclick="location.href='join.php'" type="button" value="회원가입"> </div> </form> </div> </body> </html>
- doLogin.php
<?php $dbConn = mysqli_connect("127.0.0.1", "park", "park123414", "php_blog_2021") or die("CONNECTION ERROR"); if (isset($_GET['userId']) == false) { echo "userId를 입력해주세요."; exit; } if (isset($_GET['userPw']) == false) { echo "userPw를 입력해주세요."; exit; } $userId = $_GET['userId']; $userPw = $_GET['userPw']; $sql = " select * from `member` where userId = '$userId' "; $rs = mysqli_query($dbConn, $sql); //아이디가 있다면 비밀번호 검사 if(mysqli_num_rows($rs)==1) { $row = mysqli_fetch_assoc($rs); //비밀번호가 맞다면 세션 생성 if($row['userPw']==$pw){ $_SESSION['userId']=$id; if(isset($_SESSION['userId'])){ ?> <script> alert("로그인 되었습니다."); location.replace("index.php"); </script> <?php } else{ echo "session fail"; } } else { ?> <script> alert("아이디 혹은 비밀번호가 잘못되었습니다."); history.back(); </script> <?php } } else{ ?> <script> alert("아이디 혹은 비밀번호가 잘못되었습니다."); history.back(); </script> <?php } ?>
자주하는 실수
- modify.php
- 이렇게 해야 id 값이 doModify.php로 넘어간다.
<input type="hidden" name="id" value="<?=$id?>">
큐
- detail에서 삭제기능
- 로그인 폼 [완료]
- 로그인 기능 [..]
- 회원가입 폼 [완료]
- 회원가입 기능 [완료]
내가 모르는 것
- 회원가입 후 로그인 시 오류남
느낀점
- 게시판 만들기에 속도를 더 올려야한다.
'공부기록' 카테고리의 다른 글
[공부기록] 2021-05-29 php 게시판 만들기 로그인 중복체크, 화면 구현 (0) | 2021.05.31 |
---|---|
[공부기록] 2021-05-28 php 복습 및 로그인 구현 (0) | 2021.05.31 |
[공부기록] 2021-05-26 PHP 게시시판 만들기 작성, 수정, 삭제 (0) | 2021.05.27 |
[공부기록] 2021-05-25 HTML 삭제까지 (0) | 2021.05.26 |
[공부기록] 2021-05-24 MySQL / PHP (0) | 2021.05.25 |