If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Adding to DB. Whats wrong with code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-29-08, 17:09
Nerz Nerz is offline
Registered User
 
Join Date: Jun 2008
Posts: 11
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
Reply With Quote
  #2 (permalink)  
Old 06-30-08, 01:51
myle myle is offline
(Making Your Life Easy)
 
Join Date: Feb 2004
Location: New Zealand
Posts: 1,143
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
__________________
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
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

Last edited by myle; 07-01-08 at 03:01.
Reply With Quote
  #3 (permalink)  
Old 06-30-08, 11:30
fredservillon fredservillon is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 06-30-08, 11:31
fredservillon fredservillon is offline
Registered User
 
Join Date: Oct 2005
Posts: 178
myle is correct
Reply With Quote
  #5 (permalink)  
Old 06-30-08, 11:43
Nerz Nerz is offline
Registered User
 
Join Date: Jun 2008
Posts: 11
Thanx for help
Reply With Quote
  #6 (permalink)  
Old 07-01-08, 14:25
Nerz Nerz is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 07-01-08, 14:49
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Invalid SQL
Code:
SELECT comma, separated, list, of, fields
FROM   tablename
WHERE  somecriteria = somevalue
OR     somethingelse = anotherthing
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On