Update database when a certain link is click

nicolewyp
nicolewyp used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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

Author

Commented:
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?

Author

Commented:
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?
Commented:
Okay to do any action when the link is click will require the action to occur on the client Side (The Browser), your Database is on the Server Side.  Thought it is posible to include the logic to acces the databse remotely in the javascript, it is not a good idea for security reasons.  Anyone will be able to see the conection script required and you database will be open for public inspection.  So lets try something diferent.

The page where the choice is made doesnt have to present LINKA and LINKB as links.  What you want if the users to choose between those two.  You can put that choice on a dropdown within a Form, with a sumit button that indicate "Select desire file".  Put some javascript that would prevent the submit to occur if no selection is made on the dropdown.

Now on the page where that form goes asked about the value on the dropdown and modifie the strSql accordinly.

Hope this helps.

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial