Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: part 2: insert record on load page


Message #1 by jake williamson 28 <jake.williamson@2...> on Thu, 21 Mar 2002 11:48:08 +0000
hello,

i'm still plugging on with my ip, browser and os hit page thing. i've got
the page to enter information into the database as the page loads now (which
is great!!) but what i'm trying to go is tie the ServerVariables to the
values going into the table. this is what i've set up:

' Setting variables
Dim con, sql_insert, data_source
data_source = "dsn=28design;"
sql_insert = "insert into HITS (SERVERADDRESS, BROWSER, OS) values ('ip',
'browser', 'os')"
' Creating the Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
' Executing the sql insertion code
con.Execute sql_insert
' Done. Now Close the connection
con.Close
Set con = Nothing

and these are the server requests:

<%= Request.ServerVariables("SERVER_NAME") %>
<%= Request.ServerVariables("HTTP_USER_AGENT") %>
<%= Request.ServerVariables("HTTP_UA_OS") %>

now, my guess is these should go near the top of the page and the sql should
be modified to refelect these variables - thing is, i cant get it to do it!

any ideas oh gurus (thanks for getting me this far!!)

jake

Message #2 by "Ken Schaefer" <ken@a...> on Fri, 22 Mar 2002 09:44:22 +1100
<% @Language=VBScript%>
<%
Option Explicit
%>
<!-- #include virtual="/inc/ADO/DBConnOpen.asp" -->
<!-- #include virtual="/inc/Misc/Loghits.asp" -->
<%
Dim objConn                    ' As ADODB.Connection
Dim strServerAddress
Dim strUserBrowser
Dim strUserOS

strServerAddress = Request.ServerVariables("ServerName")
strUserBrowser = Request.ServerVariables("HTTP_User_Agent")
strUserOS = Request.ServerVariables("HTTP_UA_OS")

Call DBConnOpen(objConn, data_source)
Call LogHit(objConn, strServerAddress, strUserBrowser, strUserOS)
%>


and in LogHits.asp

<%
Sub LogHits( _
    ByRef objConn, _
    ByVal strServerAddress, _
    ByVal strUserBrowser, _
    ByVal strUserOS _
    )

    Dim strSQL

    strSQL = _
        "INSERT INTO Hits " & _
        "(ServerAddress, Browser, OS) " & _
        "VALUES " & _
        "'" & strServerAddress & "', '" & strUserBrowser & "', '" &
strUserOS & "')"

    objConn.Execute strSQL,,adCmdText+adExecuteNoRecords

End Sub
%>

DBConnOpen.asp

<%
Sub DBConnOpen( _
    ByRef objConn,
    ByVal strConnString _
    )

    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open strConnectString

End Sub
%>

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "jake williamson 28" <jake.williamson@2...>
Subject: [access_asp] part 2: insert record on load page


: i'm still plugging on with my ip, browser and os hit page thing. i've got
: the page to enter information into the database as the page loads now
(which
: is great!!) but what i'm trying to go is tie the ServerVariables to the
: values going into the table. this is what i've set up:
:
: ' Setting variables
: Dim con, sql_insert, data_source
: data_source = "dsn=28design;"
: sql_insert = "insert into HITS (SERVERADDRESS, BROWSER, OS) values ('ip',
: 'browser', 'os')"
: ' Creating the Connection Object and opening the database
: Set con = Server.CreateObject("ADODB.Connection")
: con.Open data_source
: ' Executing the sql insertion code
: con.Execute sql_insert
: ' Done. Now Close the connection
: con.Close
: Set con = Nothing
:
: and these are the server requests:
:
: <%= Request.ServerVariables("SERVER_NAME") %>
: <%= Request.ServerVariables("HTTP_USER_AGENT") %>
: <%= Request.ServerVariables("HTTP_UA_OS") %>
:
: now, my guess is these should go near the top of the page and the sql
should
: be modified to refelect these variables - thing is, i cant get it to do
it!
:
: any ideas oh gurus (thanks for getting me this far!!)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Message #3 by jake williamson 28 <jake.williamson@2...> on Fri, 22 Mar 2002 10:02:13 +0000
Shalini & ken,

thanks for getting back to me; it was the apostrophe followed by quote marks
followed by & that was foxing me!

so for example, i've altered the sql to read:

(' " & Request.ServerVariables("SERVER_NAME") & " ', etc)

and it works! i've set up the page here:

http://www.ridgeback.co.uk/hits.asp

really suprissed by the traffic actually - it went up around 3ish uk time
and there's been 415 hits! the page splits it down into pages as well which
is handy for our client.

for some reason though the pc doesn't identify itself using the 'HTTP_UA_OS'
request? weird..

thanks again for you help,

jake



on 22/3/02 3:06, Shalini Noronha at snoronha@v... wrote:

> Either u can trap these in local variable and put the local variables in the
> SQL statement
> or directly embed these in ur SQL
> 
> 'So if ur local variables are
> ServerAdd     =  Request.ServerVariables("SERVER_NAME")
> Browser         =  Request.ServerVariables("HTTP_USER_AGENT")
> OS                =   Request.ServerVariables("HTTP_UA_OS")
> 
> ' Then ur SQL
> sql_insert = "insert into HITS (SERVERADDRESS, BROWSER, OS) values ('" &
> ServerAdd & "','"  & Browser & "','" &  OS & "')"
> 
> 
> 'else if u directly embed them then
> sql_insert = "insert into HITS (SERVERADDRESS, BROWSER, OS) values ('" &
> Request.ServerVariables("SERVER_NAME") & "','" &
> Request.ServerVariables("HTTP_USER_AGENT") & "','" &
> Request.ServerVariables("HTTP_UA_OS") & "'"
> 
> to test ur syntax do a response.write of sql_insert before u execute it


  Return to Index