Forums

This topic is locked

Insert record on page load-URGENT HELP

Posted 29 Apr 2004 00:53:05
1
has voted
29 Apr 2004 00:53:05 Peter Lent posted:
I am trying to collect a referral ID and IP address for people who visit a site I made.

I know how to collect the data, but I do not know how to insert that data when my index.asp page loads automatically.

Any suggestions/tips/trick?

THANKS

peter

Replies

Replied 29 Apr 2004 14:34:34
29 Apr 2004 14:34:34 Vince Baker replied:
using the request.servervariable command you can obtain the info you need.

I do exactly this on my site where when someone opens a page it automatically inserts a record into my stats table. It is just an insert sql to work when the page loads.

The code is below, feel free to take it and just change it to fit your field needs.


<!-- This script records user info for site stats -->

<%
Dim strStatUser, strStatURL
strStatUser = "0"
strStatURL = Request.ServerVariables("SCRIPT_NAME"

if Request.Cookies("useruserid" <> "" then

strStatUser = Request.Cookies("useruserid"

end if
%>

<%
sql_stats ="INSERT INTO tbl_stats (stat_user_id_fk, stat_url) VALUES (" & strStatUser & ",'" & strStatURL & "')"
%>

<%
set InsertStats = Server.CreateObject("ADODB.Command"
InsertStats.ActiveConnection = "dsn=yourdsname"
InsertStats.CommandText = sql_stats
InsertStats.CommandType = 1
InsertStats.CommandTimeout = 0
InsertStats.Prepared = true
InsertStats.Execute()
%>

Regards
Vince

Visit my home: www.chez-vince.com

VBScript | ASP | HTML | SQL | Oracle | Hosting

Edited by - bakerv on 29 Apr 2004 14:35:31

Reply to this topic