Results 1 to 6 of 6

Thread: Can anyone figure this one out?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question

    Forgive me I also posted this in another forum but I really need help fast.

    Ok..Here is the code. I sampled this from someone else on the web. You know... free code.

    My problem is that it doesn't DO what it it supposed to do.

    It doesn't end up checking for empty fields or check for passwords to match nor does it write into the DB. Why am I not making connection into the DB?

    ANy ideas???

    I am using a simple Access database within the domain. I used Frontpage 2000 as my editor.


    I really need this finished today.PLease help me.

    <!-- #INCLUDE FILE="data.asp" --> 'code for this file is below
    <% Response.Buffer = true %>
    <%
    '-- Check if Submit button pushed, if not ignore the entire script
    If Request.Form("btnAdd") = "Submit" Then

    '-- Make sure all boxes have data entered into them
    If Request.Form("name") <> "" OR Request.Form("password") <> "" OR _
    Request.Form("password2") <> "" OR _
    Request.Form("email") <> "" OR _
    Request.Form("userID") <> "" Then

    '-- Make sure the passwords match
    If Request.Form("password") = Request.Form("password2") Then

    '-- Declare your variables
    Dim DataConnection, cmdDC, RecordSet, SQL, strError
    Dim strUserName, strPassword, strEmail, strUserID

    '-- Get data from the form fields
    strUserName = Request.Form("name")
    strPassword = Request.Form("password")
    strEmail = Request.Form("email")
    strUserID = Request.Form("userID")

    '-- Create object and open database
    Set DataConnection = Server.CreateObject("ADODB.Connection")
    DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & DatabasePath & ";"

    Set cmdDC = Server.CreateObject("ADODB.Command")
    cmdDC.ActiveConnection = DataConnection

    '-- default SQL
    SQL = "SELECT * FROM UserRegistration"

    If Request.Form("name") <> "" Then
    SQL = "SELECT UserRegistration.* FROM UserRegistration WHERE " & _
    "UserRegistration.userID='" & strUserID & "' AND " & _
    "UserRegistration.password ='" & strPassword & _
    "' OR Register.email ='" & strEmail & "'"
    End If

    cmdDC.CommandText = SQL
    Set RecordSet = Server.CreateObject("ADODB.Recordset")

    '-- Cursor Type, Lock Type

    '-- ForwardOnly 0 - ReadOnly 1
    '-- KeySet 1 - Pessimistic 2
    '-- Dynamic 2 - Optimistic 3
    '-- Static 3 - BatchOptimistic 4


    RecordSet.Open cmdDC, , 0, 2

    '-- check to see if the user and password or
    ' e-mail address have registered before
    If Not RecordSet.EOF Then
    If RecordSet.fields("email")=strEmail Then
    strError = "<FONT FACE='ARIAL' SIZE='2'><B>" & _
    "Sorry this email has already been " & _
    "registered, please try again" & _
    "</B></FONT>"
    Else
    'Redo page and say that this User name
    'and Password are already taken
    strError = "<FONT FACE='ARIAL' SIZE='2'><B>" & _
    "Sorry this user name and password are " & _
    "already taken, please try again" & _
    "</B></FONT>"
    End If

    Else
    '-- Add new record to the database
    Dim Dconn, sSQL
    Set Dconn = Server.CreateObject("ADODB.Connection")
    Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
    DatabasePath & ";"

    sSQL = "INSERT INTO UserRegistration(name, email, userID, " & _
    "password, userLevel) VALUES ('" & strUserName & _
    "','" & strEmail & "','" & strUserID & _
    "','" & strPassword & "',1)"
    Dconn.Execute sSQL
    Dconn.Close
    Set Dconn = Nothing

    'Forward the user to page to notify of authentication
    Response.Redirect "thankyou.asp"
    End If
    Else
    strError = "Your passwords don't match"
    End If

    '-- Close all connections
    RecordSet.Close
    Set RecordSet = Nothing

    DataConnection.Close
    Set DataConnection = Nothing

    Else
    'Tell them what they entered wrong
    strError = "Please fill in all the boxes"
    End If
    End If

    %>

    <!-- HTML FORM -->
    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>

    <BODY bgcolor="#FFFFFF" MARGINHEIGHT="0" MARGINWIDTH="0"
    LEFTMARGIN="0" TOPMARGIN="0" TEXT="#000000">

    <%
    '-- Error message if there is any
    Response.write (strError & "<BR>")
    %>

    <form method="POST" action="thankyou.asp" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1">
    <!--webbot bot="SaveDatabase" SuggestedExt="asp"
    S-DataConnection="UserRegistration" S-RecordSource="Register"
    U-Database-URL="fpdb/UserRegistration.mdb"
    S-Builtin-Fields="HTTP_USER_AGENT REMOTE_HOST Timestamp REMOTE_USER"
    S-Builtin-DBFields="Browser_type Remote_computer_name Timestamp User_name"
    S-Form-Fields="password2 userID email password name"
    S-Form-DBFields="PASSWORD2 USERID email PASSWORD Name" -->
    <div align="left">
    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr>
    <td width="50%"><font face="Arial" size="2">Full
    Name:</font></td>
    <td width="50%"><!--webbot bot="Validation" B-Value-Required="TRUE"
    --><input type="text" name="name" size="20"></td>
    </tr>
    <tr>
    <td width="50%"><font face="Arial" size="2">Email:</font></td>
    <td width="50%"><!--webbot bot="Validation" B-Value-Required="TRUE"
    --><input type="text" name="email" size="20"></td>
    </tr>
    <tr>
    <td width="50%"><font face="Arial" size="2">Choose
    a User ID:</font></td>
    <td width="50%"><!--webbot bot="Validation" B-Value-Required="TRUE"
    --><input type="text" name="userID" size="20"></td>
    </tr>
    <tr>
    <td width="50%"><font face="Arial" size="2">Choose
    a Password:</font></td>
    <td width="50%"><!--webbot bot="Validation" B-Value-Required="TRUE"
    --><input type="password" name="password" size="20"></td>
    </tr>
    <tr>
    <td width="50%"><font face="Arial" size="2">Confirm
    Password:</font></td>
    <td width="50%"><!--webbot bot="Validation" B-Value-Required="TRUE"
    --><input type="password" name="password2" size="20"></td>
    </tr>
    </table>
    </div>
    <p><input type="submit" value="Submit" name="btnAdd">
    <input type="reset" value="Reset" name="B2"></p>
    </form>
    </body>
    </html>
    ----------------------------------------------------

    data.asp
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <%
    Const DatabasePath = "c:/inetpub/wwwroot/ReclaimAmerica.org/fpdb/UserRegistration.mdb"


    %>

    <P> </P>

    </BODY>
    </HTML>

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    hi there,
    i started to look at your code,did look it all but this:

    '-- Make sure all boxes have data entered into them
    If Request.Form("name") <> "" OR Request.Form("password") <> "" OR _
    Request.Form("password2") <> "" OR _
    Request.Form("email") <> "" OR _
    Request.Form("userID") <> "" Then

    '-- Make sure the passwords match
    If Request.Form("password") = Request.Form("password2") Then


    should be checked before submitting the form!!
    it will decrease traffic on your server,instead check
    those field with javascript and then if there all ok, submit

    ex:

    <input type="button" value="Submit" onClick="mySubmit();"

    <script language=javascript>
    function mySubmit()
    var msg;
    if(document.yourFormName.yourFieldName.value == '')
    msg += 'Please complete this field \n';
    .....check all of them......
    if(msg != '')
    alert(msg);
    else
    document.myForm.submit();
    <script>

    this will help a lot,
    i'll look at the rest of your code!!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Thanks for responding:

    I am bewildered about this

    In Frontpage, I set the form properties to send to database:

    It then automatically inserts this code at the top of the exisiting code which of course does connect and write to the DB. But I am pretty sure that the code I want to use is not being fired!

    <%
    ' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.
    On Error Resume Next

    strErrorUrl = ""

    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    If Request.Form("VTI-GROUP") = "0" Then
    Err.Clear

    Set fp_conn = Server.CreateObject("ADODB.Connection")
    FP_DumpError strErrorUrl, "Cannot create connection"

    Set fp_rs = Server.CreateObject("ADODB.Recordset")
    FP_DumpError strErrorUrl, "Cannot create record set"

    fp_conn.Open Application("UserRegistration_ConnectionString")
    FP_DumpError strErrorUrl, "Cannot open database"

    fp_rs.Open "Register", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
    FP_DumpError strErrorUrl, "Cannot open record set"

    fp_rs.AddNew
    FP_DumpError strErrorUrl, "Cannot add new record set to the database"
    Dim arFormFields0(5)
    Dim arFormDBFields0(5)
    Dim arFormValues0(5)

    arFormFields0(0) = "password2"
    arFormDBFields0(0) = "PASSWORD2"
    arFormValues0(0) = Request("password2")
    arFormFields0(1) = "userID"
    arFormDBFields0(1) = "USERID"
    arFormValues0(1) = Request("userID")
    arFormFields0(2) = "email"
    arFormDBFields0(2) = "email"
    arFormValues0(2) = Request("email")
    arFormFields0(3) = "password"
    arFormDBFields0(3) = "PASSWORD"
    arFormValues0(3) = Request("password")
    arFormFields0(4) = "name"
    arFormDBFields0(4) = "Name"
    arFormValues0(4) = Request("name")

    FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

    If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then
    FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type"
    End If
    If Request.ServerVariables("REMOTE_HOST") <> "" Then
    FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name"
    End If
    FP_SaveFieldToDB fp_rs, Now, "Timestamp"
    If Request.ServerVariables("REMOTE_USER") <> "" Then
    FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name"
    End If

    fp_rs.Update
    FP_DumpError strErrorUrl, "Cannot update the database"

    fp_rs.Close
    fp_conn.Close

    Session("FP_SavedFields")=arFormFields0
    Session("FP_SavedValues")=arFormValues0
    Response.Redirect "thankyou.asp"

    End If
    End If


    THe originator of this script set the form properties to a default.asp which he never mentioned.

    Any ideas?

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    Out of curiousity, is the db set as Read Only?
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    no it is set as archive

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking

    ok I made some changes and now I can write to the DB.
    But when I test the password checking routines I get this error:

    Error Type:
    Microsoft VBScript runtime (0x800A01A8)
    Object required: ''
    /ReclaimAmerica.org/test.asp, line 98


    ---------------------------------------------------------------

    Here is the code with line 98 flagged with a ++++++

    <!-- #INCLUDE FILE="data.asp" -->
    <% Response.Buffer = true %>
    <%
    '-- Check if Submit button pushed, if not ignore the entire script
    If Request.Form("btnAdd") = "Submit" Then

    '-- Make sure all boxes have data entered into them
    If Request.Form("name") <> "" OR Request.Form("password") <> "" OR _
    Request.Form("password2") <> "" OR _
    Request.Form("email") <> "" OR _
    Request.Form("userID") <> "" Then

    '-- Make sure the passwords match
    If Request.Form("password") = Request.Form("password2") Then

    '-- Declare your variables
    Dim DataConnection, cmdDC, RecordSet, SQL, strError
    Dim strUserName, strPassword, strEmail, strUserID

    '-- Get data from the form fields
    strUserName = Request.Form("name")
    strPassword = Request.Form("password")
    strEmail = Request.Form("email")
    strUserID = Request.Form("userID")

    '-- Create object and open database
    Set DataConnection = Server.CreateObject("ADODB.Connection")
    DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & DatabasePath & ";"


    Set cmdDC = Server.CreateObject("ADODB.Command")
    cmdDC.ActiveConnection = DataConnection

    '-- default SQL
    SQL = "SELECT * FROM UserRegistration"

    If Request.Form("name") <> "" Then
    SQL = "SELECT * FROM Register WHERE " & _
    "Register.userID='" & strUserID & "' AND " & _
    "Register.password ='" & strPassword & _
    "' OR Register.email ='" & strEmail & "'"
    End If

    cmdDC.CommandText = SQL
    Set RecordSet = Server.CreateObject("ADODB.Recordset")

    '-- Cursor Type, Lock Type

    '-- ForwardOnly 0 - ReadOnly 1
    '-- KeySet 1 - Pessimistic 2
    '-- Dynamic 2 - Optimistic 3
    '-- Static 3 - BatchOptimistic 4


    RecordSet.Open cmdDC, , 0, 2

    '-- check to see if the user and password or
    ' e-mail address have registered before
    If Not RecordSet.EOF Then
    If RecordSet.fields("email")=strEmail Then
    strError = "<FONT FACE='ARIAL' SIZE='2'><B>" & _
    "Sorry this email has already been " & _
    "registered, please try again" & _
    "</B></FONT>"
    Else
    'Redo page and say that this User name
    'and Password are already taken
    strError = "<FONT FACE='ARIAL' SIZE='2'><B>" & _
    "Sorry this user name and password are " & _
    "already taken, please try again" & _
    "</B></FONT>"
    End If

    Else
    '-- Add new record to the database
    Dim Dconn, sSQL
    Set Dconn = Server.CreateObject("ADODB.Connection")
    Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
    DatabasePath & ";"

    sSQL = "INSERT INTO Register(name, email, userID, " & _
    "password, userLevel) VALUES ('" & strUserName & _
    "','" & strEmail & "','" & strUserID & _
    "','" & strPassword & "',1)"
    Dconn.Execute sSQL
    Dconn.Close
    Set Dconn = Nothing

    'Forward the user to page to notify of authentication
    Response.Redirect "thankyou.asp"
    End If
    Else
    strError = "Your passwords don't match"
    End If

    '-- Close all connections
    ++++ RecordSet.Close
    Set RecordSet = Nothing

    DataConnection.Close
    Set DataConnection = Nothing

    Else
    'Tell them what they entered wrong
    strError = "Please fill in all the boxes"
    End If
    End If

    %>

Posting Permissions

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



Click Here to Expand Forum to Full Width