Link to home
Start Free TrialLog in
Avatar of nicolewyp
nicolewyp

asked on

Update database when a certain link is click

how do i update the database when a user login to my web site and click on certain link using ASP?

for example, on my web site, there is LinkA and LinkB. when userA login and click on LinkA, i need to update the database table called tblLink with the user name (i.e., userA) and the linkage (i.e., LinkA or LinkB).

thank you.
Avatar of CarlosMu
CarlosMu

You can do this with a simple SQL INSERT.  I presume that the screen were the user Login is not the same where he made the selection of LINKA or LINKB.  So the userid will be stored on a cookie, or Session variable.  On the page where the choice is going to be made the act of chosing a link will obviously take you to that link.  So the Insert will be made there on the LINKA.ASP page or the LINKB.ASP page.


' First you capture the user id on the form that answers
'  to the Login form
DIM strUserid
strUser = Resquest.Form("UserId")
' Store the user id on a cookie
Response.cookies("UserId") = strUser
'Redirect to the form were the choice is made
Response.redirect("choice.html")


The choice.html doesnt have to be anything more than a page where the links are available

On the LInkA.ASP page on the other hand, you obtain the user entered on the login and create the apropiated insert Statment

dim strUserId
dim cn      
dim cnStr  
dim strSql   'SQL STRING

' Please remember it is case sensitive
strUserId = Request.cookies("UserId")  
cnStr = "Wharever your conection string is"
set cn = server.CreateObject("ADODB.CONNECTION")

strSQL = "INSERT INTO tblLink (USERID, LINKAGE, "
strSql = strSql & "EVENTDATE,OTHER FIELD) VALUES ("
'Single apost are used inside double quotes becuse user id is a string
strSql = strSql & "'" & strUserId & "', "
'Since this is a sample for LinkA.asp page ....
strSql = strSql & "'LINKA.ASP', " & "'" & NOW() & "', "
'you continue this way until you fill all the fields
'Remebmer to close the parentesis
strSql = strSql & ")"

cn.Open cnStr, strSql
Avatar of nicolewyp

ASKER

dear carlosMu, thank you for your comment. however, your suggestion cannot be apply to my situation because the LinkA and LinkB do not link to another page. Instead it link to a zip file. therefore i cannot use the SQL insert method after the link is click. is it possible the update is done when the link is click?
dear carlosMu, thank you for your comment. however, your suggestion cannot be apply to my situation because the LinkA and LinkB do not link to another page. Instead it link to a zip file. therefore i cannot use the SQL insert method after the link is click. is it possible the update is done when the link is click?
ASKER CERTIFIED SOLUTION
Avatar of CarlosMu
CarlosMu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Recommendation: Accept comment from CarlosMu
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

DominicCronin
EE Cleanup Volunteer