Guest User

Untitled

a guest
May 6th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <%@ page contentType="text/html;charset=utf-8"%>
  2. <%@ page import="java.sql.*"%>
  3.  
  4. <html>
  5. <body>
  6.  
  7. <%
  8. String m_strUserID= request.getParameter("UserID");
  9. String m_strPWD= request.getParameter("Password");
  10. String m_strPWD2= request.getParameter("Password2");
  11. String m_strName= request.getParameter("Name");
  12. String m_strTel= request.getParameter("Tel");
  13. String m_strEmail= request.getParameter("Email");
  14.  
  15. String m_str="";
  16. Connection conn=null;
  17. Statement stmt=null;
  18. ResultSet rs=null;
  19.  
  20. boolean insertMark= true;
  21.  
  22. try{
  23.  
  24. Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  25. String url ="jdbc:mysql://localhost/member";
  26. conn= DriverManager.getConnection(url,"root","");
  27. stmt=conn.createStatement();
  28. String sql="select * from member where userid='"+m_strUserID+"'";
  29. rs=stmt.executeQuery(sql);
  30. if(rs.next()){
  31. m_str= "此帳號 "+m_strUserID+ " 已有人申請過了,請按上一頁重新申請。<br>";
  32. insertMark=false;
  33. }
  34. rs.close();
  35. sql="select * from member where email='"+m_strEmail+"'";
  36. rs=stmt.executeQuery(sql);
  37.  
  38. if(rs.next()){
  39. m_str+= "此 Email信箱 "+m_strEmail+ " 已有人申請過了,請按上一頁重新申請。<br>";
  40. insertMark=false;
  41. }
  42.  
  43. if(!m_strPWD.equals(m_strPWD2)){
  44. m_str+= "您前後兩次輸入的密碼不相同,請按上一頁重新申請。";
  45. insertMark=false;
  46. }
  47.  
  48. if(insertMark){
  49. sql="Insert into member(userid,password,name,tel,email) values('"+m_strUserID+"','"+m_strPWD+"','"+m_strName+"','"+m_strTel+"','"+m_strEmail+"')";
  50. if (rs != null) rs.close();
  51. if (stmt != null) stmt.close();
  52. stmt = conn.createStatement();
  53. stmt.executeUpdate(sql);
  54.  
  55. m_str="註冊完畢。";
  56. }
  57. }
  58.  
  59. catch (ClassNotFoundException e1) {
  60. m_str="資料庫驅動失敗,請通知網站管理員: "+"<br>" + e1.getMessage();
  61. }
  62.  
  63. catch (SQLException e2) {
  64. m_str="SQL指令錯誤,請參考以下訊息:" +"<br>"+ e2.getMessage();
  65. }
  66.  
  67. finally {
  68. try {
  69. if (rs != null) rs.close();
  70. if (stmt != null) stmt.close();
  71. if (conn != null) conn.close();
  72. }
  73. catch (SQLException ignored) {}
  74. }
  75.  
  76. %>
  77.  
  78. <%= m_str%>
  79.  
  80. </body>
  81. </html>
Add Comment
Please, Sign In to add comment