Checking DB content against form data

Author Message
joestmc

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 10/28/2008
  • Status: offline
Checking DB content against form data Tuesday, October 28, 2008 1:57 AM (permalink)
0
Hi,
I'm working on a page that will check a database for a unique record containing EVERY one of the four elements that were submitted to the page through an HTML form.

If the record is located, the ASP variable "SecurityCheck" should change from 0 to 1.
 
Here is the page so far. I appreciate any comments on how sound the VB coding is. Second to that, any thoughts on how to finish the SQL query are appreciated also.

Here's the code:
__________________________________________________________
<%@ Language=VBScript %>

<%


dim adoConn
dim rsTest
dim strSQL
dim sProctorID
dim sProctorPW
dim sLMSCourseCode
dim sStudentID
dim sSecurityCheck


sProctorID=Verify.form("ProctorID")'
sProctorPW=Verify.form("ProctorPW")'
sLMSCourseCode=Verfiy.form("LMSCourseCode")
sStudentID=Verfiy.form("StudentID")
sSecurityCheck=0


Set adoConn = Server.CreateObject("ADODB.Connection")
adoConn.Open "DBQ=" & Server.Mappath("ProtcorDB.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"


strSQL = "select ProctorID, ProctorPW, LMSCourseCode, StudentID From RequestRecords
where ProctorID = "&Verify.Form("ProctorID") AND
where ProctorPW = "&Verify.Form("ProctorPW") AND
where LMSCourseCode = "&Verify.Form("LMSCourseCode") AND
where StudentID = "&Verify.Form("StudentID");
"


Set rsTest = Conn.Execute(strSQL)
Set rsTest = Nothing


adoConn.Close
Set adoConn = Nothing

%>
 
#1
    ehvbs

    • Total Posts : 3320
    • Scores: 112
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    RE: Checking DB content against form data Tuesday, October 28, 2008 3:45 AM (permalink)
    0
    Hi joestmc,

    Consider:

    (1) using OLEDB instead of Access Driver

    (2) using an ADOCMD instead of a plain SQL statement

    (3) using and validating (!) your variables ( sProctorID,...) instead of concatenating
          the - untested - content of your form elements into the SQL statement

    (4) a statement like

              SELECT COUNT( ProctorID ) WHERE ProctorID = ? AND ...

         and setting SecurityCheck according to rsTest.Fields( 0 ).Value

    Good luck!

    ehvbs

     
     
    #2
      joestmc

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 10/28/2008
      • Status: offline
      RE: Checking DB content against form data Tuesday, October 28, 2008 7:00 AM (permalink)
      0
      Here's the latest version of the code.  It's coming together well, thank you for your feedback:
      _______________________________
      <%@ Language=VBScript %>
      <%

      dim adoConn
      dim rsTest
      dim strSQL
      dim sProctorID
      dim sProctorPW
      dim sLMSCourseCode
      dim sStudentID
      dim sSecurityCheck

      sProctorID=Request.form("ProctorID")
      sProctorPW=Request.form("ProctorPW")
      sLMSCourseCode=Request.form("LMSCourseCode")
      sStudentID=Request.form("StudentID")
      sSecurityCheck=0

      Set adoConn = Server.CreateObject("ADODB.Connection")
      adoConn.Open "DBQ=" & Server.Mappath("ProtcorDB.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
       
      strSQL = "select Count* From RequestRecords
      where ProctorID = sProctorID AND
      ProctorPW = sProctorPW AND
      LMSCourseCode = sLMSCourseCode AND
      StudentID = sStudentID;
      "
      Set rsTest = Conn.Execute(strSQL)
      if rsTest.eof then
          sSecurityCheck=0
      if else
      rsTest(0)=0 then sSecurityCheck=0
      else
      rsTest(0).>0 then  sSecurityCheck=1

      adoConn.Close
      Set adoConn = Nothing
      %>
       
      #3
        ehvbs

        • Total Posts : 3320
        • Scores: 112
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        RE: Checking DB content against form data Wednesday, October 29, 2008 3:44 AM (permalink)
        0
        Hi joestmc,

        you are welcome. I trust that you'll post a revised version of code, as
        soon as you have dealt with the syntax errors (SQL and VBScript).

        Regards

        ehvbs
         
        #4
          joestmc

          • Total Posts : 3
          • Scores: 0
          • Reward points : 0
          • Joined: 10/28/2008
          • Status: offline
          RE: Checking DB content against form data Friday, October 31, 2008 3:40 AM (permalink)
          0
          Is that to say that you see errors (VB & SQL) in the code in it's current form?

          I haven't started testing this yet, so I can't speak to how it is or isn't working but I appreciate any advice regarding errors that you see in that code.

          Please let me know what you see errors or weaknesses.
           
          #5
            ehvbs

            • Total Posts : 3320
            • Scores: 112
            • Reward points : 0
            • Joined: 6/22/2005
            • Location: Germany
            • Status: offline
            RE: Checking DB content against form data Saturday, November 01, 2008 4:26 AM (permalink)
            0
            Hi joestmc,

            think about:

              (1) validating the user input

              (2) syntax of "select count"

              (3) syntax of if ... then ... else

              (4) the "." operator

            Good luck!

            ehvbs

             
            #6

              Online Bookmarks Sharing: Share/Bookmark

              Jump to:

              Current active users

              There are 0 members and 1 guests.

              Icon Legend and Permission

              • New Messages
              • No New Messages
              • Hot Topic w/ New Messages
              • Hot Topic w/o New Messages
              • Locked w/ New Messages
              • Locked w/o New Messages
              • Read Message
              • Post New Thread
              • Reply to message
              • Post New Poll
              • Submit Vote
              • Post reward post
              • Delete my own posts
              • Delete my own threads
              • Rate post

              2000-2012 ASPPlayground.NET Forum Version 3.9