Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - Whats wrong with this code?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Whats wrong with this code?

 Post Reply Post Reply Page  12>
Author
Nerz View Drop Down
Newbie
Newbie


Joined: 23 June 2008
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nerz Quote  Post ReplyReply Direct Link To This Post Topic: Whats wrong with this code?
    Posted: 29 June 2008 at 9:30pm
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>

Back to Top
Nerz View Drop Down
Newbie
Newbie


Joined: 23 June 2008
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote Nerz Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2008 at 9:41pm
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
  • Back to Top
    socialanimal View Drop Down
    Newbie
    Newbie
    Avatar

    Joined: 14 October 2007
    Location: Leeds, UK
    Status: Offline
    Points: 39
    Post Options Post Options   Thanks (0) Thanks(0)   Quote socialanimal Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2008 at 9:46pm
    Change

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

    To

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

    The way you've done it it's trying to match up the column IP to a column called address
    Back to Top
    Nerz View Drop Down
    Newbie
    Newbie


    Joined: 23 June 2008
    Status: Offline
    Points: 28
    Post Options Post Options   Thanks (0) Thanks(0)   Quote Nerz Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2008 at 9:56pm
    It's now giving this error...
     
    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /checkexist.asp, line 35, column 14
    sql_check = ""Select IP from tblIP where IP = '" & Address &"'""
    -------------^
    Back to Top
    socialanimal View Drop Down
    Newbie
    Newbie
    Avatar

    Joined: 14 October 2007
    Location: Leeds, UK
    Status: Offline
    Points: 39
    Post Options Post Options   Thanks (0) Thanks(0)   Quote socialanimal Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2008 at 10:48pm
    Yup cos now you have double quotes at the start of your query, where there should only be one

    I wrote - sql_check = "Select IP from tblIP where IP = '" & Address &"'"
    You used sql_check = ""Select IP from tblIP where IP = '" & Address &"'""
    Back to Top
    Nerz View Drop Down
    Newbie
    Newbie


    Joined: 23 June 2008
    Status: Offline
    Points: 28
    Post Options Post Options   Thanks (0) Thanks(0)   Quote Nerz Quote  Post ReplyReply Direct Link To This Post Posted: 30 June 2008 at 2:58pm
    That worked thank you.
    Back to Top
    Nerz View Drop Down
    Newbie
    Newbie


    Joined: 23 June 2008
    Status: Offline
    Points: 28
    Post Options Post Options   Thanks (0) Thanks(0)   Quote Nerz Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2008 at 7:23pm
    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
    Back to Top
    socialanimal View Drop Down
    Newbie
    Newbie
    Avatar

    Joined: 14 October 2007
    Location: Leeds, UK
    Status: Offline
    Points: 39
    Post Options Post Options   Thanks (0) Thanks(0)   Quote socialanimal Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2008 at 7:51pm
    But your SQL string isn't valid SQL

    The following is but it still doesn't make sense if your unique identifier "ID" field should be the only WHERE parameter, if your wanting to bring back the "ID" field too then it should look like ....

    sql_check2 = "Select ID, IP from tblIP where ID = " & Request.Form("ID")
    Back to Top
     Post Reply Post Reply Page  12>

    Forum Jump Forum Permissions View Drop Down

    Forum Software by Web Wiz Forums® version 12.07
    Copyright ©2001-2024 Web Wiz Ltd.


    Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
    About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

    Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
    Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

    Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

    Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.