Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2008
    Posts
    11

    Unanswered: Adding to DB. Whats wrong with code

    What i'm trying to do is check if data, particularly the IP address that is accessing the page. If the address exists it pretty much does nothing so far. If it doesn't it adds it to the database.

    <html>
    <head>
    <title>Check Page</title>
    </head>
    <body bgcolor="white" text="black">
    <%
    'Dimension variables
    Dim adoCon 'Holds the Database Connection Object
    Dim rsProjDatabase 'Holds the recordset for the records in the database
    Dim sql_check 'Holds the SQL query to check the database
    'Dim sql_insert
    Dim Address 'Hold IP Address

    'Get ip address
    Address= Request.ServerVariables("REMOTE_ADDR")

    'Create an ADO connection object
    Set adoCon = Server.CreateObject("ADODB.Connection")

    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("ProjDatabase.mdb")

    'Create an ADO recordset object
    Set rsProjDatabase = Server.CreateObject("ADODB.Recordset")

    'Set the cursor type we are using so we can navigate through the recordset
    rsProjDatabase.CursorType = 2

    'Set the lock type so that the record is locked by ADO when it is updated
    rsProjDatabase.LockType = 3


    'Initialise the strSQL variable with an SQL statement to query the database
    sql_check = "Select IP from tblIP where IP = Address"

    'Open the recordset with the SQL query
    rsProjDatabase.Open sql_check, adoCon

    If rsProjDatabase.EOF Then

    'Tell the recordset we are adding a new record to it
    rsProjDatabase.AddNew

    'Add a new record to the recordset
    rsProjDatabase.Fields("IP") = Address

    'Write the updated recordset to the database
    rsProjDatabase.Update

    Else
    Response.Write ("It exist")

    End If


    'Reset server objects
    rsProjDatabase.Close
    Set rsProjDatabase = Nothing
    Set adoCon = Nothing
    %>

    </body>
    </html>

    It's giving me the error...
    Error Type:
    Microsoft JET Database Engine (0x80040E10)
    No value given for one or more required parameters.
    /checkexist.asp, line 38

    line 38 is

    rsProjDatabase.Open sql_check, adoCon

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,422
    Provided Answers: 7
    look like the sql is wrong

    sql_check = "Select IP from tblIP where IP = Address"

    try

    sql_check = "Select IP from tblIP where IP = '" & Address & "'"

    but i Do
    is
    sql_check = "Select IP from tblIP where IP = '[Address]'"

    then

    sql_check = replace(sql_check,"[Address]",Address)

    it just make it easyer to read
    also you get the ' in the right place

    good commenting that stop it
    Don't stop the Commenting your code
    Last edited by myle; 07-01-08 at 04:01.
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Oct 2005
    Posts
    178
    do a response.write of the variable Address before writing to database to make sure it's not null. If not Null check for your syntax specially the quotation marks within the variable strings.

  4. #4
    Join Date
    Oct 2005
    Posts
    178
    myle is correct

  5. #5
    Join Date
    Jun 2008
    Posts
    11
    Thanx for help

  6. #6
    Join Date
    Jun 2008
    Posts
    11
    One more thing. I added to the sql statement. This is the line...

    sql_check2 = "Select IP from tblIP where IP = '" & Address &"' and ID from tblIP where IP = Request.Form("ID")"

    It says i'm getting this error
    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /checkexist2.asp, line 49, column 106
    sql_check2 = "Select IP from tblIP where IP = '" & Address &"' and ID from tblIP where IP = Request.Form("ID")""
    ---------------------------------------------------------------------------------------------------------^

    I don't understand considering i have the proper amount of start and end "s

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Invalid SQL
    Code:
    SELECT comma, separated, list, of, fields
    FROM   tablename
    WHERE  somecriteria = somevalue
    OR     somethingelse = anotherthing
    George
    Home | Blog

Posting Permissions

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