안녕하세요. JohnComputer 입니다.
바로 앞에 올렸던 게시글을 참고하시면 도움이 됩니다.
https://johncom.tistory.com/23
앞에서 설명했기에 소스코드 바로 첨부하겠습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <!DOCTYPE html> <html> <body> <h2>HTML Forms</h2> <form action="login_check.php" name="login_form" method="post"> <label for="fname">ID:</label><br> <input type="text" id="id_val" name="id_val" placeholder="아이디"><br> <!-- input 박스 안 글자 넣기 = placeholder --> <label for="lname">Password:</label><br> <input type="password" id="pw_val" name="pw_val" placeholder="비밀번호"><br><br> <input type="button" value="로그인" onclick="check_input()"> </form> <script type="text/javascript"> function check_input() { if (!document.login_form.id_val.value) // login_form 이름을 가진 form 안의 id_val 의 value가 없으면 { alert("아이디를 입력하세요!"); document.login_form.id_val.focus(); // 화면 커서 이동 return; } if (!document.login_form.pw_val.value) { alert("비밀번호를 입력하세요!"); // 화면 커서 이동 return; } document.login_form.submit(); // 모두 확인 후 submit() } </script> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <?php $id_val = $_POST["id_val"]; $pw_val = $_POST["pw_val"]; print_r($id_val); // 화면에 값 보여주기 print_r($pw_val); $con = mysqli_connect("localhost(DB서버)", "root(DB아이디)", "1234(DB페스워드)", "TEMPDATA(DB명)"); $sql = "select * from members(테이블명) where id='$id_val'"; $result = mysqli_query($con, $sql); $num_match = mysqli_num_rows($result); if(!$num_match) { echo(" <script> window.alert('등록되지 않은 아이디입니다!') history.go(-1) </script> "); } else { $row = mysqli_fetch_array($result); $db_pass = $row["pw_val"]; // DB칼럼명 if($passwd != $db_pass) { echo(" <script> window.alert('비밀번호가 틀립니다!') history.go(-1) </script> "); exit; } else { session_start(); $_SESSION["id"] = $row["id_val"]; $_SESSION["name"] = $row["name"]; // SESSION에 저장. mysqli_close($con); echo(" <script> location.href = './login.php'; </script> "); } } ?> | cs |
'프로그래밍 > HTML,CSS ,PHP,JQuery,Javascript' 카테고리의 다른 글
PHP POST content-length 파일 업로드 용량 오류. (0) | 2021.02.17 |
---|---|
LED 저항값 계산기 (블로그) - 아두이노 (0) | 2020.09.20 |
PHP form 전송 방법 POST / GET 이용방법 (0) | 2020.09.04 |
키보드 타이핑 효과 글자쓰기 효과 Typeit 예시 사용법 (0) | 2020.09.03 |
HTML javascript 자바스크립트 로그인 화면 form 구성 빈칸 체크 focus placeholder (0) | 2020.08.28 |