Jump to content

form validation


jayeshp100

Recommended Posts

This is my asp code<html><head><title>Form to database</title></head><body> <%dim oConndim oRsSet oConn = Server.CreateObject("ADODB.Connection")oConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}"oConn.ConnectionString = oConn.ConnectionString & ";DBQ=" & server.MapPath("database.mdb")oConn.Openset oRs = oConn.Execute("INSERT INTO Members(Username,Pword,name,Street,Town,County,PostCode,Member_Telephone_No,Email,PersonelInformation) VALUES('" & request.Form("Username") & "','" & request.Form("Pword") & "', '" & request.Form("name") & "','" & request.Form("Street") & "','" & request.Form("Town") & "', '" & request.Form("County") & "', '" & request.Form("PostCode") & "','" & request.Form("Member_Telephone_No") & "' , '" & request.Form("email") & "','" & request.Form("PersonelInformation") & "')") response.redirect "home.asp"%></body></html>I want to validate the form to check that the username and password are currently not in the DB and the rest of the the form has correct data inputted and some data is intserted

Link to comment
Share on other sites

something like this:

If IsEmpty(request.form("field_name")) or request.form("field_name")="" then	response.write "<div align='center'field cannot be blank !!<br/>"	response.write "<input type='button' onClick='window.history.back()'>"	response.write "</div>"	response.end  Else	local_var = request.Form("field_name")End If

Link to comment
Share on other sites

something like this:
If IsEmpty(request.form("field_name")) or request.form("field_name")="" then	response.write "<div align='center'field cannot be blank !!<br/>"	response.write "<input type='button' onClick='window.history.back()'>"	response.write "</div>"	response.end  Else	local_var = request.Form("field_name")End If

So this code checks to see if the form is filled in, what about the username and password i want to check that they don't match any existing data in the already in the DB, also if you have an tel no field that only numbers can be enterd.
Link to comment
Share on other sites

To check if the username already exists....SQL = "SELECT fldUSERNAME FROM TBL WHERE fldUSERNAME='" & request.Form("Username") & "'Set RS = Server.CreateObject("ADODB.Recordset")RS.Open SQL, MyConn IF NOT RS.recordcount <=0 THENErrmsg="Username Already Exists"END IF

Link to comment
Share on other sites

If IsEmpty(request.form("field_name")) or request.form("field_name")="" thenresponse.write "<div align='center'field cannot be blank !!<br/>"response.write "<input type='button' onClick='window.history.back()'>"response.write "</div>"response.end Elselocal_var = request.Form("field_name")End IfThe the above code i get Type mismatch: '[string: ""]' all fields a text type.

Link to comment
Share on other sites

hi to check the error in the form , you can use java script code , you can find it in www.hotscripts.comto insert data into database via html form , use this code , but this code use DNS Connection , so its dosent use ODBC Setting ********a.aspHTML Form code<html><head><title>test</title></head><body bgcolor="white" text="black"> <form name="form" method="post" action="add.asp"> Name: <input type="text" name="name" > <br> Comments: <input type="text" name="com"><br> <input type="submit" name="Submit" value="Submit"> </form> </body></html>*****add.asp page code <html><body><%Dim conn Dim rs Dim strSet Conn = Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/webdata/it.mdb"))set rs = Server.CreateObject("ADODB.recordset") RS.open "samer",Conn,2,2rs.AddNewrs.Fields("Name") = Request.Form("name")rs.Fields("Com") = Request.Form("com")rs.Updaters.CloseSet rs = NothingSet Con = NothingResponse.Redirect "a.asp"%></body></html> :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...