View Single Post
Join Date: Dec 2008
Posts: 2
Reputation: kardus is an unknown quantity at this point 
Solved Threads: 0
kardus kardus is offline Offline
Newbie Poster

Re: [ask]validation for user name registration

 
0
  #2
Dec 2nd, 2008
  1. register.jsp
  2.  
  3. <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Untitled Document</title>
  9. <style type="text/css">
  10. <!--
  11. body {
  12. background-image: url();
  13. }
  14. -->
  15. </style></head>
  16.  
  17. <body>
  18. <table width="800" height="1028" border="0" align="center">
  19. <tr>
  20. <td width="795" height="134"><img src="banner2.gif" width="795" height="95" align="top" /><br />
  21. <img src="home.gif" width="132" height="35" /><img src="team.gif" width="132" height="35" /><img src="players.gif" width="132" height="35" /><img src="message.gif" width="132" height="35" /><img src="tranfer.gif" width="132" height="35" /><img src="about.gif" width="135" height="35" /></td>
  22. </tr>
  23. <tr>
  24. <td height="788" align="left" valign="top"><form id="form1" name="form1" method="post" action="doregister.jsp">
  25. <p>&nbsp;</p>
  26. <table width="200" border="1">
  27. <tr>
  28. <td colspan="2"><div align="center">Register</div></td>
  29. </tr>
  30. <tr>
  31. <td width="83">Username</td>
  32. <td width="101"><label>
  33. <input type="text" name="txtuser" id="txtuser" />
  34. </label></td>
  35. </tr>
  36. <tr>
  37. <td>Password</td>
  38. <td><label>
  39. <input type="password" name="txtpass" id="txtpass" />
  40. </label></td>
  41. </tr>
  42. <tr>
  43. <td>Age</td>
  44. <td><label>
  45. <input type="text" name="txtage" id="txtage" />
  46. </label></td>
  47. </tr>
  48. <tr>
  49. <td>Club</td>
  50. <td><label>
  51. <select name="selectclub" id="selectclub">
  52. <option>Manchaster United</option>
  53. <option>Inter Milan</option>
  54. </select>
  55. </label></td>
  56. </tr>
  57. <tr>
  58. <td colspan="2"><label>
  59. <div align="center">
  60. <input type="submit" name="button" id="button" value="Submit" />
  61. </div>
  62. </label></td>
  63. </tr>
  64. <tr>
  65. <td height="62" colspan="2"> <%
  66. String error = request.getParameter("err");
  67. if(error!=null) out.println(error);
  68. %></td>
  69. </tr>
  70. </table>
  71. </form>
  72. <p> </p></td>
  73. </tr>
  74. <tr>
  75. <td height="80" align="left" valign="top"><p>&nbsp;</p>
  76. <p>
  77. </p></td>
  78. </tr>
  79. </table>
  80. </body>
  81. </html>
  82.  
  83.  
  84. doregister.jsp
  85.  
  86. <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
  87. <%@ include file ="konek.jsp" %>
  88.  
  89. <%
  90. String user = request.getParameter("txtuser");
  91. String pass = request.getParameter("txtpass");
  92. String age = request.getParameter("txtage");
  93. String query = null;
  94.  
  95.  
  96. if(user == null || user.equals(""))
  97. {
  98. response.sendRedirect("register.jsp?err = please fill the username");
  99. }
  100.  
  101. else if (user != null)
  102. {
  103. query = "select username from msUser where username like '%"+user+"%'";
  104. }
  105.  
  106. else if(pass == null || pass.equals(""))
  107. {
  108. response.sendRedirect("register.jsp?err = please fill the pass");
  109. }
  110. else if(age == null || age.equals(""))
  111. {
  112. response.sendRedirect("register.jsp?err = please fill the age");
  113. }
  114.  
  115.  
  116. else
  117. {
  118. if(user == query)
  119. {
  120. response.sendRedirect("register.jsp?err = please choose a diffrent user name");
  121. }
  122. else if(user != query)
  123. {
  124. st.executeUpdate("insert into msUser values('"+user+"','"+pass+"',"+age+")");
  125. con.close();
  126. response.sendRedirect("home.jsp");
  127. }
  128. }
  129.  
  130. %>

sorry, no need to download the attachement...here is the code..
Reply With Quote