Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting IP address into Database

Status
Not open for further replies.

spencern

Programmer
Dec 20, 2001
78
US
Hi,
On the first page of my site, I want to insert the users IP address into a database. I made a command under server behaviors and put the following code under sql:
INSERT INTO visitor (IPAddress)
VALUES (IP)

Then down below in the variable section I put
IP as the name and
Request.ServerVariables("REMOTE_ADDR")
as the runtime variable.

When I run the page I get:
[Microsoft][ODBC Microsoft Access Driver] Syntax error in number in query expression '172.169.68.58'.
I have the field in the database set as number.

Does anyone see anything that I'm doing wrong?
I can post the code for the page if it helps.
Thanks,
Spencer
 
Just guessing but isnt an ip address text not a number The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
You're probably right about the text field in the database, but I still get a query expression error.
Here is the code from the page. It should add the ip address to the database and then redirect to the next page, but it's getting stuck on the command code.

<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<!--#include file=&quot;../Connections/Insurance.asp&quot; -->

<html> <head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%

if(Request.ServerVariables(&quot;REMOTE_ADDR&quot;) <> &quot;&quot;) then Command1__MMColParam = Request.ServerVariables(&quot;REMOTE_ADDR&quot;)

%>
<%

set Command1 = Server.CreateObject(&quot;ADODB.Command&quot;)
Command1.ActiveConnection = MM_Insurance_STRING
Command1.CommandText = &quot;INSERT INTO visitor (IPAddress) VALUES (&quot; + Replace(Command1__MMColParam, &quot;'&quot;, &quot;''&quot;) + &quot;) &quot;
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>
<p>  </p>
<p> </p>
<p> </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
<%response.Redirect(welcome.asp)%>

Any ideas? I've tried a lot of combinations trying to get it to work, but so far nothing.

Thanks a lot for your help,
Spencer
 
Have you tried specifying the db field as text? The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Yep, my suggestion as well. It's the only way that you can lift a number as complex as an IP address.

M &quot;There are 3 kinds of people; those that can count and those that can't&quot;
 
Yep I tried setting it to text and it's still a no-go.
I'm still trying some other ideas, but do you have any thoughts about the code?
Thanks,
Spencer
 
yup try this

set Command1 = Server.CreateObject(&quot;ADODB.Command&quot;)
Command1.ActiveConnection = MM_Insurance_STRING
Command1.CommandText = &quot;INSERT INTO visitor (IPAddress) VALUES('&quot; & Command1__MMColParam & &quot;'&quot;
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top