<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.PreparedStatement"%>
<%@ page import="java.sql.ResultSet"%>

<% request.setCharacterEncoding("utf-8"); %>


<%
	String id = (String)session.getAttribute("valid_id");
	String password = request.getParameter("password");
	String name = request.getParameter("name");
	String year = request.getParameter("year");
	String month = request.getParameter("month");
	String day = request.getParameter("day");
	String email = request.getParameter("email1");
	///////////////////////////////////
	String mail = request.getParameter("email");
	if(request.getParameter("email").equals("9")){//직접입력을 선택하면, Form페이지의 변수 email값은 null이된다.
		mail = request.getParameter("email2");  //그러므로 email2의 값을 가져와서 대입한다.
	}
	///////////////////////////////////
	String phone_number = request.getParameter("phone_number");
	
	String str="";

	try{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","20161505","961120");
		PreparedStatement pstmt = conn.prepareStatement("insert into log_member(id,password,name,year,month,day,email,mail,phone_number,authority) values(?,?,?,?,?,?,?,?,?,0)");
		pstmt.setString(1, id);
		pstmt.setString(2, password);
		pstmt.setString(3, name);
		pstmt.setString(4, year);
		pstmt.setString(5, month);
		pstmt.setString(6, day);
		pstmt.setString(7, email);
		pstmt.setString(8, mail);
		pstmt.setString(9, phone_number);
		
		pstmt.executeUpdate();
		pstmt.close();
		conn.close();
		
		session.invalidate();//아이디 중복확인을 위해 세션에 저장한 id값을 삭제
		%>
		
		<script>
			alert("회원가입에 성공하였습니다.");
			location.href="../../Home.jsp";
		</script>
		
	<% } catch(Exception e) {
		e.printStackTrace();%>
		<script>
			alert("회원가입에 실패하였습니다. 다시 시도해 주세요.");
		</script>
		
	<%}%>
<!DOCTYPE html>
<html>
<head>
<title>레코드 추가</title>
</head>
<body>
	<%=str %>	<p>
	
	<A href="../../list.jsp">회원목록보기 </A>

</body>
</html>



