Validating Form data against Database

Results 1 to 3 of 3

Thread: Validating Form data against Database

  1. #1
    Join Date
    Dec 1969
    Posts
    412

    Default Validating Form data against Database

    I need to come up with a way to validate the user&#039s login ID. I know you guys have tons of articles on validating form input, I&#039ve read them, and can&#039t seem to find what I need. Here&#039s the thing: each user has to login to the site through a form using their laboratory name. I need to verify that the lab name they enter is the same as the lab name in the database. I&#039ve been trying a few methods, and here&#039s what I&#039ve come up with so far. Can you tell me where I went wrong?<BR><BR>&#060;%<BR>dim DbConn<BR>set DbConn = Server.CreateObject("ADODB Connection")<BR>DbConn.ConnectionString = "DSN=labs"<BR>DbConn.Open<BR><BR>dim strlogin<BR>dim strSQL<BR>set strSQL = "Select CallID from CallLog"<BR>strlogin = strSQL<BR><BR>If Request.Form("frmLabID") &#060;&#062; strlogin Then<BR>Response.Redirect "validate.asp"<BR>%&#062;<BR><BR>By the way, I already have a redirect page set up for some other functionality, and that&#039s where I&#039m putting this code. Should I put it somewhere else?<BR><BR>Thanks for all of your help

  2. #2
    Sathiya Guest

    Default RE: Validating Form data against Database

    I think you dont need to send the control to naother page for validation you can do it in the SQL itself<BR>&#060;%<BR>If Request("Form1") &#060;&#062; "" then<BR> If Request("Form1") = "submit" then<BR> sqlstr = "Select * from &#060;tablename&#062; where &#060;colname or<BR> LabName = "<BR> sqlstr = sqlstr & "&#039" & Trim(Request("Labname") & "&#039"<BR> set rsLab = DBConn.execute(sqlstr)<BR> <BR> If rsLab.eof then<BR> Redirect them to error page <BR> Else<BR> Redirect them to correct page<BR> End if<BR>%&#062;<BR>&#060;form action="post"&#062;<BR>&#060;input type = "textbox" name="LabName" value=""&#062;<BR>&#060;input type = "Submit" name ="Form" value="submit"&#062;<BR>&#060;/form&#062;

  3. #3
    Jess Magnaye Guest

    Default RE: Validating Form data against Database

    I think you can also use the following script. Pardon me, for I don&#039t usually use "dims". :)<BR><BR>&#060;%<BR>set DbConn = Server.CreateObject("ADODB Connection")<BR>DbConn.ConnectionString = "DSN=labs"<BR>DbConn.Open<BR><BR>set strSQL = "Select CallID from CallLog"<BR>strlogin = dbconn.execute(strSQL)<BR><BR>DO WHILE NOT strlogin.eof<BR> login=strlogin<BR><BR> If REquest.form("frmLabID") &#060;&#062; strlogin Then<BR> Response.write "enter valid login ID"<BR> end if<BR><BR>strlogin.movenext<BR>LOOP<BR><BR>strlogi n.close<BR>dbconn.close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •