-
Notifications
You must be signed in to change notification settings - Fork 0
/
addMember.jsp
95 lines (67 loc) · 2.3 KB
/
addMember.jsp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<%@ page
language="java"
import="java.io.*,java.util.*,javax.servlet.http.*,javax.servlet.*,java.sql.*"
session="true"
%>
<%
String pag=null;
String log = (String)session.getAttribute("log");
String type = (String)session.getAttribute("type");
RequestDispatcher r;
if(log == null ){
pag="err.jsp?msg=You are not Autherized to Access this page"+log+" "+type;
}
else if(type == null || type.equals("false") ){
pag="err.jsp?msg=You are not Autherized to Access this page"+log+" "+type;
}
%>
<%
if(pag!=null)
{
r = request.getRequestDispatcher(pag);
r.forward(request,response);
}
String firstname=request.getParameter("firstname");
String lastname=request.getParameter("lastname");
String dob=request.getParameter("dob");
String mobile=request.getParameter("phone");
String typ =request.getParameter("UserType");
String age="0";
String gender=request.getParameter("gender");
String country=request.getParameter("country");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/bank";
Connection con=DriverManager.getConnection(url, "root", "root");
Statement st=con.createStatement();
PreparedStatement pst=con.prepareStatement("Select * from user where firstname=? and lastname=?");
pst.setString(1, firstname);
pst.setString(2, lastname);
ResultSet rsp = pst.executeQuery();
if(rsp.next())
{
r = request.getRequestDispatcher("err.jsp?msg=user already exists");
r.forward(request,response);
}
else{
int id=1000;
String que = "SELECT * FROM user ORDER BY id DESC LIMIT 0, 1";
ResultSet rpst=st.executeQuery(que);
if(rpst.next())
{
id =rpst.getInt("id");
id+=1;
session.setAttribute("id",id);
}
String query = "INSERT INTO user(id , firstname,lastname,age,gender,nationality,dob,mobile,email,type)VALUES('"+id+ "','"+firstname+ "','"+lastname+ "','"+age+ "','"+gender+ "','" +country+ "','" +dob+ "','" +mobile+ "','" +email+ "','"+typ+"')" ;
int rs = st.executeUpdate( query );
if(rs>=1)
{ r = request.getRequestDispatcher("sucessFamily.jsp");
r.forward(request,response); }
else
{
r = request.getRequestDispatcher("err.jsp?msg=Addition failed!");
r.forward(request,response);
}
}
%>