jayeshp100 Posted March 8, 2006 Share Posted March 8, 2006 ive got a form thats adds inofrmation to a Access database how do make sure the information is valid and if the information is wrong it won't add to the DB. Link to comment Share on other sites More sharing options...
jayeshp100 Posted March 8, 2006 Author Share Posted March 8, 2006 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 More sharing options...
netcracker Posted March 8, 2006 Share Posted March 8, 2006 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 More sharing options...
jayeshp100 Posted March 8, 2006 Author Share Posted March 8, 2006 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 <{POST_SNAPBACK}> 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 More sharing options...
pulpfiction Posted March 8, 2006 Share Posted March 8, 2006 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 More sharing options...
jayeshp100 Posted March 9, 2006 Author Share Posted March 9, 2006 How do you check that a person has enterd correct data like phone number must have no text, also in my form page do i have put some ASP code before my form. Link to comment Share on other sites More sharing options...
jayeshp100 Posted March 9, 2006 Author Share Posted March 9, 2006 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 More sharing options...
pulpfiction Posted March 9, 2006 Share Posted March 9, 2006 Try this,VAL = Request.Form("FLDNAME")IF (Len(VAL) = 0) OR (IsNull(VAL)) THENError.... Link to comment Share on other sites More sharing options...
jayeshp100 Posted March 10, 2006 Author Share Posted March 10, 2006 How do i check that someone has enterd the date in the correct format in a asp form?Also if you have a text field and a user enters a number i want a n error message prompting the user not to use numbers. Link to comment Share on other sites More sharing options...
Matar Posted March 11, 2006 Share Posted March 11, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now