<%@ 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.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<% request.setCharacterEncoding("utf-8");%>
<%
String id = (String)session.getAttribute("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 authority = (String)session.getAttribute("authority");
ResultSet rs=null;

String sql=null;
try{
	   Class.forName("oracle.jdbc.driver.OracleDriver");
	   Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","20161505","961120");
	   sql="select * from log_member where id=? ";
	   PreparedStatement pstmt=conn.prepareStatement(sql);
	   pstmt.setString(1, id);
	   
	   rs=pstmt.executeQuery(); //결과 가져옴
	  
	  if(rs.next()){
	  String dbPass=rs.getString("password");

	  	  pstmt=conn.prepareStatement("update log_member set password=?, name=?, year=?, month=?, day=?, email=?, mail=?, phone_number=? where id=? ");
		                                    //UPDATE 테이블명 SET 컬럼명=새로운값 WHERE 업데이트조건 
		  pstmt.setString(9,id);
		  pstmt.setString(1,password);
		  pstmt.setString(2,name);
		  pstmt.setString(3,year);
		  pstmt.setString(4,month);
		  pstmt.setString(5,day);
		  pstmt.setString(6,email);
		  pstmt.setString(7,mail);
		  pstmt.setString(8,phone_number);
		  
		  pstmt.executeUpdate(); 
		  
		  	session.setAttribute("id",id);
			session.setAttribute("password",password);
			session.setAttribute("authority",authority);
		  %>

		<script>
			alert("정보가 수정되었습니다.");
			location.href="../../Home.jsp";
		</script>
	 <%
	}

}catch(Exception e){
%><script>
	alert("정보가 일치하지 않습니다.");
	location.href="editForm.jsp";
</script><%
	e.printStackTrace();
}finally{
}
%>