Where'd They Come From?: Recording Referrals in ASP - What's Involved? (Page 2 of 4 )
To be able to understand what is going to be happening in this tutorial, you will need to have a basic grasp of ASP, but since this is an ASP tutorial, I will take for granted that you have some level of ASP knowledge. That, really, is all that is required, other than a database program; I used MS Access, on Windows XP. A simple text editor like notepad will suffice for the coding, that is all I have ever used, and I’ve done just fine.
Generally I like to begin my projects with a template or at least have each page already created, even if they are empty. So we will create our files now, in the same directory as your index.asp file (or equivalent) create an ASP page name referrals.asp, another ASP page named ref.asp, and a database named ref.mdb, we are now ready to begin.
First we will play about with our database and set names. Create a new table in the database and name it reftable, in this table we require columns named ‘Ref_ID’ (this should be your key) this should have the Data Type of AutoNumber, ‘URL’ with Data Type of Memo, and finally ‘Counter’ with Data Type of Number.
To begin with, we must set a control URL, so that we don’t end up with an error when trying to run the code for the first time (we will get an error stating that the database is empty, this can be avoided by adding a little extra code, but I find this method faster and easier). Simply enter “Control” in the URL column, and 0 in the counter column. The database is now set, we should not need to touch this again.
Open the referrals.asp page we created earlier; this is the page that is actually displayed to the user (or Administrator, whoever you allow access) so make it look all pretty if you wish, but for now lets just concentrate on making it function properly.
In the body of your file, create a simple table like the one below that I use:
The above creates the table and appropriate headings; Referring URL and Count. Below we will display the details from the database, first we need to connect to the database...
This step is a little more advanced so we will make it a little easier by making it a DSNless connection (this saves us time required to make a DSN connection, then coding that to look at the correct database, then getting our code right to use this DSN connection...too much effort I believe, for the same end result!)
Any of you who have dabbled in ASP would have come across a database connection before, so we will fly through the connection, and not worry too much on what is involved.
We connect to the database using this DSNless connection: