<%@page import="org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdatesByKind"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
	String id = request.getParameter("id");
	String password = request.getParameter("password");
	String name = request.getParameter("name");
	String birth = request.getParameter("birth");
	String gender = request.getParameter("gender");
	String email = request.getParameter("email");
	String phone = request.getParameter("phone");
	
	String str = "";
		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("select * from membership where id=?");
			pstmt.setString(1, id);
			ResultSet rs = pstmt.executeQuery();

			if(rs.next()){
				  String dbPass=rs.getString("password");
				  if(password.equals(dbPass)){
					  if(id.equals("admin") && !session.getAttribute("id").equals("admin")) {
						  %><script>alert("관리자 수정불가");
						   location.href="main.jsp";</script> <%
					  } else {
					  	  pstmt=conn.prepareStatement("update membership set name=?, birth=?, gender=?, email=?, phone=? where id=?");
						  pstmt.setString(1,name);
						  pstmt.setString(2,birth);
						  pstmt.setString(3,gender);
						  pstmt.setString(4,email);
						  pstmt.setString(5,phone);
						  pstmt.setString(6,id);
						  
						  pstmt.executeUpdate();
						  %><script>alert("정보수정성공!!");
						  location.href="main.jsp";</script> <%
					  }
				 }else{
					 %><script>alert("비밀번호 확인바람");
					 location.href="updateForm.jsp";</script> <%
				 }}

		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
</body>
</html>