<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%
	request.setCharacterEncoding("utf-8");
%>

<%
	String id = request.getParameter("id");
	String password = request.getParameter("password");
	String name = request.getParameter("name");
	String birth = request.getParameter("yyyy") + "/" + request.getParameter("mm") + "/" + request.getParameter("dd");
	String gender = request.getParameter("gender");
	String email = request.getParameter("email1") + "@" + request.getParameter("email2");
	String phone = request.getParameter("pNum1") + "-" + request.getParameter("pNum2") + "-" + request.getParameter("pNum3");

	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl", "20152488", "960504");
		PreparedStatement pstmt = conn.prepareStatement("insert into membership(id,password,name,birth,gender,email,phone) values(?,?,?,?,?,?,?)");
		if (password.length() > 4) {
			if(id=="" || name=="" || request.getParameter("yyyy")=="" || request.getParameter("dd")=="" || request.getParameter("email1")==""
					|| request.getParameter("pNum1")=="" || request.getParameter("pNum2")=="" || request.getParameter("pNum3")=="") {
				%><script>alert("회원가입실패");
				location.href="inputForm.jsp";</script> <% 
			} else {
				pstmt.setString(1, id);
				pstmt.setString(2, password);
				pstmt.setString(3, name);
				pstmt.setString(4, birth);
				pstmt.setString(5, gender);
				pstmt.setString(6, email);
				pstmt.setString(7, phone);
	
				pstmt.executeUpdate();
				pstmt.close();
				conn.close();
				
				%><script>alert("회원가입성공!!");
				location.href="loginForm.jsp";</script> <%
			}
		} else {
			%><script>alert("회원가입실패");
			location.href="inputForm.jsp";</script> <% 
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>

</body>
</html>