473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

JSP Form Validation

ak1dnar
1,584 Expert 1GB
I am sending two form field values to this jsp page and i need to insert that values to MySQL DB Table.
form fields.
Expand|Select|Wrap|Line Numbers
  1. Name
  2. Email
before insert these two thing i need to check whether those fields are blank or not.
Again i need to check whether email address already taken or not.

All the Error messages should display as a in this page and then i can pass it back to HTML page using responseText;

I can check the email id from the table and here after i can't find out a way to do next validations. please help.

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*" %>
  2. <%@ include file="../config/conn.jsp" %>
  3. <%
  4. String driver = mysql_driver;
  5. Class.forName(driver).newInstance();
  6. Connection con=null;
  7.  
  8. ResultSet rst=null;
  9. Statement stmt=null;
  10.  
  11. int count;
  12. String db_email=null;
  13.  
  14. String name=request.getParameter("c_name");
  15. String email=request.getParameter("c_email");
  16.  
  17. try
  18. {
  19.     String url=mysql_con_string;
  20.     con=DriverManager.getConnection(url);
  21.     stmt=con.createStatement();
  22. }
  23. catch(Exception e)
  24. {
  25.     out.println(e.getMessage());
  26. }
  27.  
  28. if(request.getParameter("c_submit") != null)
  29. {  
  30.     rst=stmt.executeQuery("select c_email from clients where c_email ='"+email+"'");              
  31.     while(rst.next())
  32.     {
  33.     db_email = rst.getString("c_email");
  34.                 if (email.equals(db_email))
  35.                 {
  36.                 out.println("<font face=\"verdana\" size=\"2\" color=\"red\"><b>Already Taken</b></font>");
  37.                 break;
  38.                 }
  39.  
  40.     }
  41.  
  42.     //Inserting Records
  43.  
  44.         if(db_email==null)
  45.         {
  46.         count =  stmt.executeUpdate("insert into clients(c_name,c_email) values('"+name+"','"+email+"')");
  47.         if(count == 1)
  48.         {
  49.             rst=stmt.executeQuery("select c_name from clients where c_email ='"+email+"'");
  50.             while(rst.next())
  51.             {
  52.             out.println("<B>"+rst.getString("c_name")+"</B>"+" Client Registerd:::");
  53.             }
  54.         }
  55.         }
  56.  
  57. }
  58. else
  59. {
  60. out.println("<font face=\"verdana\" size=\"2\" color=\"red\"><b> UnAuthorized Access !</b></font>");
  61. }
  62. %>
  63.  
Apr 6 '07 #1
0 6226

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.