Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 1st, 2004, 10:58 AM
Authorized User
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting to a database onclicking a URL

Hi Vijay & all,

 I am showing some dynamic links from the database.On clicking these links users can download a file(report).What i want to do is as soon as they
  click i want to insert that jobid and their username as well the system date on to an access databse table called LOg.This is to track the no. of downloads
  for a report.Here is the code.

 How can i proceed.Pls help with code.Thanks

<%@ Language=VBScript %>
<% Response.Buffer = True %>

If Session("user") = "" Then
    Response.Redirect "login.html"
End If
<table border=1>
<th>Report Name</th><th>Date Created</th>

Dim objConn ' Connection Name
Dim strConn ' Connection String
Dim objRS ' Recordset Variable
Dim strSQL ' variable for SQL statement
Dim intTotalColumns
Dim intCounter
Const adOpenStatic = 3
Const adLockReadOnly = 1
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("asp.mdb") & ";"
objConn.Open strConn

strSQL = "SELECT a.ReportName, a.url2,a.dt,a.jobid FROM table1 AS a, email AS b WHERE a.jobid=b.jobid and b.UNAME='" & Session("user") & "' order by a.ReportName"
objRS.open strSQL, objConn, adOpenStatic, adLockReadOnly

if objRS.EOF then
Response.write "No Subscriptions in your account"
end if
do while not objRS.EOF
<tr><td><a href="http://mycompany/mydept/reports/reports/<%=objRS("url2")%>"><%=objRS("url2")%></A></td>
<td><%=objRS("dt") %></td><td><input type=hidden name="what" value="<%=objRS("jobid")%> "></td>


Set objRS = Nothing

Set objConn = Nothing


Old October 1st, 2004, 11:24 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post

Check out this post File download counting

If that doesn't help you, let me give you the logic on how to do that, and you can refer the other post for some help. Though if you are stuck up somewhere, we are there to help.

<a href="http://mycompany/mydept/reports/reports/<%=objRS("url2")%>"><%=objRS("url2")%></A>

Instead of showing the link directly here, have a link to another asp file, with the same querystring along with JobId and username, say...
<a href="download.asp?Url=<%=objRS("url2")%>"&JobId== "<%=objRS("jobid")%>&UserName=<%=Session("user")%> ></A>

Then within download.asp, first insert these JobId, UserName and SystemDate into the respective table. Then refer to the my other post shown above for code to initiate the download popup, from where the user can download the file. Use the URL that comes along with querystring to the download.asp to pass to the downloadFile function (code listed in the other post).

Also you don't need to use a hidden field there as used in your code.

As I am rushing up from work (end of the day) I couldn't explain in detail. Bear with me!:)

Hope that helps.

- Vijay G
Strive for Perfection

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in inserting to Database?? Hannibal Pro JSP 0 March 14th, 2006 07:11 AM
Inserting into a database jroxit Classic ASP Basics 1 January 2nd, 2006 06:04 PM
inserting into database shieldsteven VS.NET 2002/2003 0 November 11th, 2004 07:44 PM
inserting into database shieldsteven VS.NET 2002/2003 8 October 20th, 2004 05:33 PM
Inserting into database ZiqXx C# 6 July 5th, 2004 04:13 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.