-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.jsp
61 lines (59 loc) · 2.74 KB
/
update.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
<%@page contentType="text/html" import="java.sql.*,java.util.*;" pageEncoding="UTF-8"%>
<%
try{
String email = null;
Cookie c[] = request.getCookies();
for(int i=0;i<c.length;i++){
if(c[i].getName().equals("user")){
email = c[i].getValue();
break;
}
}
if(email==null){
response.sendRedirect("index.jsp");
}
else{
if(request.getParameter("username").length()==0 || request.getParameter("gender").length()==0 || request.getParameter("dob").length()==0 || request.getParameter("caste").length()==0 ||
request.getParameter("religion").length()==0 || request.getParameter("occupation").length()==0 || request.getParameter("state").length()==0 || request.getParameter("country").length()==0){
response.sendRedirect("edit_profile.jsp?empty=1");
}
else{
String username = request.getParameter("username");
String gender = request.getParameter("gender");
String dob = request.getParameter("dob");
String caste = request.getParameter("caste");
String religion = request.getParameter("religion");
String occupation = request.getParameter("occupation");
String state = request.getParameter("state");
String country = request.getParameter("country");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/wedding","root","");
PreparedStatement ps = cn.prepareStatement("update user set username=?,gender=?,dob=?,caste=?,religion=?,occupation=?,state=?,country=? where email=?");
ps.setString(1, username);
ps.setString(2, gender);
ps.setString(3, dob);
ps.setString(4, caste);
ps.setString(5, religion);
ps.setString(6, occupation);
ps.setString(7, state);
ps.setString(8, country);
ps.setString(9, email);
if(ps.executeUpdate()>0){
response.sendRedirect("edit_profile.jsp?success=1");
}
else{
response.sendRedirect("edit_profile.jsp?again=1");
}
}
catch(Exception e){
out.println(e.getMessage());
}
}
}
}
catch(NullPointerException e){
response.sendRedirect("edit_profile.jsp");
// out.println(e.getMessage());
}
%>