Showing posts with label ASP Tutorials. Show all posts
Showing posts with label ASP Tutorials. Show all posts

Wednesday, 30 November 2011

SPECIAL CHARACTERS

When you use Active Server Pages, there are many special characters that you need to be aware of. Here is a list and description of the most common:

'

The single quotation mark signifies a comment within ASP code. Comments are generally used for organizational purposes in web design so that webmasters can share work easily and check for bugs in their system

&

The ampersand symbol is a concatenation operator that is used to combine two expressions into a string result. Here is an example from our ASPEmail script:
Mail.Body = "Email: " & strEmail & vbCrLf & "Name: " & strName

_

The underscore signifies that a one single piece of code is being written on more than one line. In ASP, many portions of code are designed to be written on one single line. If the line becomes too long and runs off the page, you can simple enter an underscore at the end of the line, return to the next line, and then continue writing your code. Although the code is written on more than one line, it will still function as one line of code.

vbCrLf

vbCrLf simply returns to the next line. This is most commonly used when displaying data such as in an email message. If you have two form fields that you want to display on separate lines in an email, simply add a vbCrLf between their code in your ASP page.

http://www.aspwebpro.com/tutorials/asp/specialcharacters.asp

INTERVAL VALUES FOR DATES / TIMES

When you work with dates and times, it is vital to know the correct value that represents the date or time period you are wanting. Here is a list of available date / time values:
Value
Meaning
"yyyy"
Year
"q"
Quarter
"m"
Month
"y"
Day of Year
"d"
Day
"w"
Weekday
"ww"
Week of Year
"h"
Hour
"n"
Minute
"s"
Seconds

Here is an example of how this may be used:

<% Response.Write DateAdd ("d", 1, Date) %>

This displays tomorrows date like this: 01/12/2011

http://www.aspwebpro.com/tutorials/asp/intervalvaluesfordates.asp

INTERVAL VALUES FOR DATES / TIMES

When you work with dates and times, it is vital to know the correct value that represents the date or time period you are wanting. Here is a list of available date / time values:
Value
Meaning
"yyyy"
Year
"q"
Quarter
"m"
Month
"y"
Day of Year
"d"
Day
"w"
Weekday
"ww"
Week of Year
"h"
Hour
"n"
Minute
"s"
Seconds

Here is an example of how this may be used:

<% Response.Write DateAdd ("d", 1, Date) %>

This displays tomorrows date like this: 01/12/2011

http://www.aspwebpro.com/tutorials/asp/intervalvaluesfordates.asp

SPECIAL CHARACTERS

When you use Active Server Pages, there are many special characters that you need to be aware of. Here is a list and description of the most common:

'

The single quotation mark signifies a comment within ASP code. Comments are generally used for organizational purposes in web design so that webmasters can share work easily and check for bugs in their system

&

The ampersand symbol is a concatenation operator that is used to combine two expressions into a string result. Here is an example from our ASPEmail script:
Mail.Body = "Email: " & strEmail & vbCrLf & "Name: " & strName

_

The underscore signifies that a one single piece of code is being written on more than one line. In ASP, many portions of code are designed to be written on one single line. If the line becomes too long and runs off the page, you can simple enter an underscore at the end of the line, return to the next line, and then continue writing your code. Although the code is written on more than one line, it will still function as one line of code.

vbCrLf

vbCrLf simply returns to the next line. This is most commonly used when displaying data such as in an email message. If you have two form fields that you want to display on separate lines in an email, simply add a vbCrLf between their code in your ASP page.

http://www.aspwebpro.com/tutorials/asp/specialcharacters.asp

INCLUDE FILES

If you are getting into web development, especially with ASP programming, include files are going to become one of your best friends. In essence, an include file allows you to write an ASP script one time and then include it in multiple web pages without having to rewrite all the code.

So when and how do you do this? One of the most basic examples is placing your database connection within an include statement and then using a simple include statement to include your connection string in your web pages.

First, you create a folder named /includes within your root directory.

Next, you create a new file named connection.asp and save it within your new /includes folder.

All that is left is to input a simple one line include statement into each page where you need to have a database connection. Here is how the include statement looks:




The include statement cannot be placed inside of your <% %>. If you need to place an include statement within your ASP code, you need to close your ASP code, input the include statement, and reopen your ASP code like this:
<%' ASP code here%>

<%' ASP code here%>

OK, you've got that. Now what is the advantage of using an include file like this? Well, think about it. Let's say your website is 100 pages and that 6 months from now something is your database conenction chages. Rather than having to go through and edit your connection string in all 100 pages, you can simply edit it one time in your include file and that will automatically update it throughout your website.

There are two way of including files in a web page. You can use INCLUDE VIRTUAL or INCLUDE FILE. Our preference is to use INCLUDE VIRTUAL. This means that you can just enter the virtual path of your website to the file you want to include. In the example of the path is "/includes/connection.asp".

http://www.aspwebpro.com/tutorials/asp/includefiles.asp

INCLUDE FILES

If you are getting into web development, especially with ASP programming, include files are going to become one of your best friends. In essence, an include file allows you to write an ASP script one time and then include it in multiple web pages without having to rewrite all the code.

So when and how do you do this? One of the most basic examples is placing your database connection within an include statement and then using a simple include statement to include your connection string in your web pages.

First, you create a folder named /includes within your root directory.

Next, you create a new file named connection.asp and save it within your new /includes folder.

All that is left is to input a simple one line include statement into each page where you need to have a database connection. Here is how the include statement looks:




The include statement cannot be placed inside of your <% %>. If you need to place an include statement within your ASP code, you need to close your ASP code, input the include statement, and reopen your ASP code like this:
<%' ASP code here%>

<%' ASP code here%>

OK, you've got that. Now what is the advantage of using an include file like this? Well, think about it. Let's say your website is 100 pages and that 6 months from now something is your database conenction chages. Rather than having to go through and edit your connection string in all 100 pages, you can simply edit it one time in your include file and that will automatically update it throughout your website.

There are two way of including files in a web page. You can use INCLUDE VIRTUAL or INCLUDE FILE. Our preference is to use INCLUDE VIRTUAL. This means that you can just enter the virtual path of your website to the file you want to include. In the example of the path is "/includes/connection.asp".

http://www.aspwebpro.com/tutorials/asp/includefiles.asp

GLOBAL.ASA

The global.asa file is a special file that handles session and application events. This file must be spelled exactly as it is here on this page and it must be located in your websites root driectory. This is a very useful file and can be used to accomplish a variety of tasks.

For example, we use the global.asa file on this website to display the number of Active Users on our site. Rather than inputting data into a database and keeping a stored record of it, our global.asa file acts as a monitor of how many users are visiting any page our website. There are no records stored in any database or text file, the information just flows in and out. Take a look at the code below we use to do this:



What the global.asa file does is create a session for each new user that is actively surfing any part of our website. Then, the session will time out or end either when the user leaves our website or at the default setting of 20 minutes.

There are several other things you can use the global.asa file for, but this tutorial was just intended to show you what makes this file special and to give you an idea of what it is used for

http://www.aspwebpro.com/tutorials/asp/globalasa.asp

PASS VARIABLES WITH QUERYSTRING

Ok, so you want to pass variables between your web pages with the using the QueryString method or the URL bar for you folks still learning ASP lingo. Well, it's as easy as it is passing variables using the form method. One of the most simple and popular ways of passing variables using the querystring method is by using a basic hyperlink.

Let's keep things simple and say that you sell books and movies on your website. Rather than creating a books.asp page and a movies.asp page to list your available products, you can put all your products into a database and display them all on one page accoring to what the user wants to see. So how do we do this?

The first thing you need to do is create your home.asp page and paste the code below into your page:


Home Page


Choose a product category to view our products:

Books
or
Movies



Notice that both links point to the same products.asp page. However, they each have a variable attached to the link with a different value. When you click on the Books link, you will see the variable and its respective value displayed in your URL bar like this: http://www.yoursite.com/products.asp?Products=Books

Now, how do get this to display your books on your products.asp page? It's a little more complicated so take it slow.

The next step is to create your products.asp page and paste the following code:

<% DIM strProducts strProducts = Request.QueryString("Products") %>


Products Page


<% IF strProducts = "Books" THEN ' Display books here ELSE ' Display movies here END IF %>,

Thank you for contacting us. We have received your message and will send a reply to your email address, <% Response.Write strEmail %>, as soon as possible.




That's all there is to it. Now, you can pass variables from one page to another using the QueryString method. If you are eager to learn more about how to actually display data from your database on your page, be sure to check out our Displaying Data From Database Tutorial.

If you want to learn another way to pass variables between pages, be sure to check out our Passing Variables with Form Tutorial.

http://www.aspwebpro.com/tutorials/asp/passvariableswqs.asp

PASS VARIABLES WITH QUERYSTRING

Ok, so you want to pass variables between your web pages with the using the QueryString method or the URL bar for you folks still learning ASP lingo. Well, it's as easy as it is passing variables using the form method. One of the most simple and popular ways of passing variables using the querystring method is by using a basic hyperlink.

Let's keep things simple and say that you sell books and movies on your website. Rather than creating a books.asp page and a movies.asp page to list your available products, you can put all your products into a database and display them all on one page accoring to what the user wants to see. So how do we do this?

The first thing you need to do is create your home.asp page and paste the code below into your page:


Home Page


Choose a product category to view our products:

Books
or
Movies



Notice that both links point to the same products.asp page. However, they each have a variable attached to the link with a different value. When you click on the Books link, you will see the variable and its respective value displayed in your URL bar like this: http://www.yoursite.com/products.asp?Products=Books

Now, how do get this to display your books on your products.asp page? It's a little more complicated so take it slow.

The next step is to create your products.asp page and paste the following code:

<% DIM strProducts strProducts = Request.QueryString("Products") %>


Products Page


<% IF strProducts = "Books" THEN ' Display books here ELSE ' Display movies here END IF %>,

Thank you for contacting us. We have received your message and will send a reply to your email address, <% Response.Write strEmail %>, as soon as possible.




That's all there is to it. Now, you can pass variables from one page to another using the QueryString method. If you are eager to learn more about how to actually display data from your database on your page, be sure to check out our Displaying Data From Database Tutorial.

If you want to learn another way to pass variables between pages, be sure to check out our Passing Variables with Form Tutorial.

http://www.aspwebpro.com/tutorials/asp/passvariableswqs.asp

GLOBAL.ASA

The global.asa file is a special file that handles session and application events. This file must be spelled exactly as it is here on this page and it must be located in your websites root driectory. This is a very useful file and can be used to accomplish a variety of tasks.

For example, we use the global.asa file on this website to display the number of Active Users on our site. Rather than inputting data into a database and keeping a stored record of it, our global.asa file acts as a monitor of how many users are visiting any page our website. There are no records stored in any database or text file, the information just flows in and out. Take a look at the code below we use to do this:



What the global.asa file does is create a session for each new user that is actively surfing any part of our website. Then, the session will time out or end either when the user leaves our website or at the default setting of 20 minutes.

There are several other things you can use the global.asa file for, but this tutorial was just intended to show you what makes this file special and to give you an idea of what it is used for

http://www.aspwebpro.com/tutorials/asp/globalasa.asp

PASS VARIABLES WITH FORM

Ok, so you want to pass variables between your web pages. Good news, it's a piece of cake with ASP. As with just about everything else in ASP, there are many ways to do this. In this tutorial, we will show you how to pass variables from one page to another using a simple form.

Let's say you have a contact form on your website and you want to personalize the confirmation page for the user. The first thing you need to do is create a contact.asp page and paste the code below into your page:


Contact Us


Email
First Name:
Last Name:
Subject:
Comments:




Now, you've got your basic form. Simple enough, right? Next, create a contactconfirm.asp page and paste the code below:

<% DIM strEmail, strFirstName, strLastName, strSubject strEmail = Request.Form("Email") strFirstName = Request.Form("FirstName") strLastName = Request.Form("LastName") strSubject = Request.Form("Subject") %>


Confirmation


<% Response.Write strFirstName %>,

Thank you for contacting us. We have received your message and will send a reply to your email address, <% Response.Write strEmail %>, as soon as possible.




This is a nice way to personalize the users experience by displaying the first name and email address that they entered on the form page.

When passing variables with a form, the Request.Form initiates the request for the form data and the ("Email") specifies the form field we are requesting. In this case, we created our own variables: strEmail, strFirstName, etc and set their values equal to the data from their respective form field. Rather than creating your own variables and setting each of their values, you could simply place <% Request.Form("Email") %> directly in your confirmation page instead of the <% Response.Write strEmail %>. Again, this is a matter of personal preference. However, we recommend you use the variable technique, especially when you start dealing with more complex ASP pages.

Now, you can pass variables from page to page within your website. Piece of cake!

f you want to learn another way to pass variables between pages, be sure to check out our Passing Variables with QueryString Tutorial.

http://www.aspwebpro.com/tutorials/asp/passvariableswform.asp

PASS VARIABLES WITH FORM

Ok, so you want to pass variables between your web pages. Good news, it's a piece of cake with ASP. As with just about everything else in ASP, there are many ways to do this. In this tutorial, we will show you how to pass variables from one page to another using a simple form.

Let's say you have a contact form on your website and you want to personalize the confirmation page for the user. The first thing you need to do is create a contact.asp page and paste the code below into your page:


Contact Us


Email
First Name:
Last Name:
Subject:
Comments:




Now, you've got your basic form. Simple enough, right? Next, create a contactconfirm.asp page and paste the code below:

<% DIM strEmail, strFirstName, strLastName, strSubject strEmail = Request.Form("Email") strFirstName = Request.Form("FirstName") strLastName = Request.Form("LastName") strSubject = Request.Form("Subject") %>


Confirmation


<% Response.Write strFirstName %>,

Thank you for contacting us. We have received your message and will send a reply to your email address, <% Response.Write strEmail %>, as soon as possible.




This is a nice way to personalize the users experience by displaying the first name and email address that they entered on the form page.

When passing variables with a form, the Request.Form initiates the request for the form data and the ("Email") specifies the form field we are requesting. In this case, we created our own variables: strEmail, strFirstName, etc and set their values equal to the data from their respective form field. Rather than creating your own variables and setting each of their values, you could simply place <% Request.Form("Email") %> directly in your confirmation page instead of the <% Response.Write strEmail %>. Again, this is a matter of personal preference. However, we recommend you use the variable technique, especially when you start dealing with more complex ASP pages.

Now, you can pass variables from page to page within your website. Piece of cake!

f you want to learn another way to pass variables between pages, be sure to check out our Passing Variables with QueryString Tutorial.

http://www.aspwebpro.com/tutorials/asp/passvariableswform.asp

NEW WAY TO HANDLE VARIABLES

The EASIEST way to deal with variables!!

Allow me to introduce myself.

My name is Rob Collyer, I lay eyes upon ASP years ago and have been heavily coding since.
It always struck me as a complete pain in the neck the way in which we have all been dealing with variables in ASP, for as long as we have used ASP.

What do I mean? ........ Allow me to explain with this example of the hard way:-

<% FirstName = Request.Form("FirstName") Surname = Request.Form("Surname") Address1 = Request.Form("Address1") Address2 = Request.Fomr(Address2") ... ... %>

Rather than go on longer than necessary into yet more lines looking exactly the same as the ones above, to put my point across, I'll put you out of your misery.

Why do variables have to be this TEDIOUS to deal with??? I wanted a way to read in all variables at once in one go, with just one function call.... I must be mad.... sure enough, I was told this as well as things like 'It's not possible', etc.

Sure enough, at the time, it wasn't possible. To my rescue came Microsoft, with Version 5 of the VBScript engine and a new command called Execute. Execute(string) basically executes a string as though it were ASP.. So Execute("Response.write ""Hello"") .... would have the same effect as just using response.write "hello"

As soon as I saw this new feature I knew instantly what I could do with it:-

<% For Each Field in Request.Form TheString = Field & "= Request.Form(""" & Field & """)" Execute(TheString) Next %>

We are setting variables automatically. That one little tiny piece of code, has saved me so much time over the last year, you will not believe.
Ok, it does have it flaws, Forms with image submit buttons pass form variable names like "submit.X", and "submit.Y" (Co-ordinates where you clicked on the submit image) which obviously wont do for variable names in ASP, and results in the white error page from hell.... But we can start to prevent these things:-

<% For Each Field in Request.Form tmpField = Replace(Field,".","") 'remove full stops TheString = tmpField & "= Request.Form(""" & Field & """)" Execute(TheString) Next %>

Why stop there?? There are many silly characters that are fine in HTML controls as names, but when setting variable names automatically like this in VBScript, these characters will not do. You can easily add additional lines as above to escape other characters like spaces, hyphens and all manner of other ones too.

You've got multiple controls on forms.... how are you gonna assign variables to multiple select boxes?
As a developer, I found it handy to read these 'multiple' part form variables into an array... I will build upon the above code to handle multiple items and create arrays from them:-

<% For Each Field in Request.Form tmpField = Replace(Field,".","") 'remove full stops ItemCount=Request.Form(Field).count IF ItemCount > 1 then
execute "redim " & field & "(" & itemcount -1 & ")" 'Dynamically dimension the array
For Item = 0 To ItemCount - 1
TheString = tmpField & "("&Item&")= request.form(""" & field & """).item(" & Item + 1& ")"
Next
Else
TheString = tmpField & "= Request.Form(""" & Field & """)"
End If
Execute(TheString)
Next
%>

I hope by now you can see the potential of what all of the above means to you as the developer.....
I urge you all to write your own functions that'll handle variables the way you want them to, and please remember.... FORMS were just an example, don't stop there, after all there are Querystrings, Cookies, Session variables, Application Variables, ServerVariables. Then there are recordsets (why not?) and the dictionary objects, etc, etc, etc.

Just remember, you are now armed with info which will save you a great deal of time, why not get busy writing some variable handling functions of your own??

If anybody wants a function to selectively handle Form, Querystring, Cookies, Session, Application and Server variables then I have one...just mail me. It also has a parameter to run in DEBUG mode which will show you variables in all objects, their values and whether their names present a problem during conversion. It'll also flag those controls that can be set to arrays, etc.

Anyway, those that do feel inspired to get writing their own handlers, let me ask one thing.... Send me a copy of your finished function(s), this is pretty new stuff and I'm well open to being inspired by YOUR code.

Feel free to contact me with your feedback.

Enjoy!
http://www.aspwebpro.com/tutorials/asp/newwaytohandlevar.asp

NEW WAY TO HANDLE VARIABLES

The EASIEST way to deal with variables!!

Allow me to introduce myself.

My name is Rob Collyer, I lay eyes upon ASP years ago and have been heavily coding since.
It always struck me as a complete pain in the neck the way in which we have all been dealing with variables in ASP, for as long as we have used ASP.

What do I mean? ........ Allow me to explain with this example of the hard way:-

<% FirstName = Request.Form("FirstName") Surname = Request.Form("Surname") Address1 = Request.Form("Address1") Address2 = Request.Fomr(Address2") ... ... %>

Rather than go on longer than necessary into yet more lines looking exactly the same as the ones above, to put my point across, I'll put you out of your misery.

Why do variables have to be this TEDIOUS to deal with??? I wanted a way to read in all variables at once in one go, with just one function call.... I must be mad.... sure enough, I was told this as well as things like 'It's not possible', etc.

Sure enough, at the time, it wasn't possible. To my rescue came Microsoft, with Version 5 of the VBScript engine and a new command called Execute. Execute(string) basically executes a string as though it were ASP.. So Execute("Response.write ""Hello"") .... would have the same effect as just using response.write "hello"

As soon as I saw this new feature I knew instantly what I could do with it:-

<% For Each Field in Request.Form TheString = Field & "= Request.Form(""" & Field & """)" Execute(TheString) Next %>

We are setting variables automatically. That one little tiny piece of code, has saved me so much time over the last year, you will not believe.
Ok, it does have it flaws, Forms with image submit buttons pass form variable names like "submit.X", and "submit.Y" (Co-ordinates where you clicked on the submit image) which obviously wont do for variable names in ASP, and results in the white error page from hell.... But we can start to prevent these things:-

<% For Each Field in Request.Form tmpField = Replace(Field,".","") 'remove full stops TheString = tmpField & "= Request.Form(""" & Field & """)" Execute(TheString) Next %>

Why stop there?? There are many silly characters that are fine in HTML controls as names, but when setting variable names automatically like this in VBScript, these characters will not do. You can easily add additional lines as above to escape other characters like spaces, hyphens and all manner of other ones too.

You've got multiple controls on forms.... how are you gonna assign variables to multiple select boxes?
As a developer, I found it handy to read these 'multiple' part form variables into an array... I will build upon the above code to handle multiple items and create arrays from them:-

<% For Each Field in Request.Form tmpField = Replace(Field,".","") 'remove full stops ItemCount=Request.Form(Field).count IF ItemCount > 1 then
execute "redim " & field & "(" & itemcount -1 & ")" 'Dynamically dimension the array
For Item = 0 To ItemCount - 1
TheString = tmpField & "("&Item&")= request.form(""" & field & """).item(" & Item + 1& ")"
Next
Else
TheString = tmpField & "= Request.Form(""" & Field & """)"
End If
Execute(TheString)
Next
%>

I hope by now you can see the potential of what all of the above means to you as the developer.....
I urge you all to write your own functions that'll handle variables the way you want them to, and please remember.... FORMS were just an example, don't stop there, after all there are Querystrings, Cookies, Session variables, Application Variables, ServerVariables. Then there are recordsets (why not?) and the dictionary objects, etc, etc, etc.

Just remember, you are now armed with info which will save you a great deal of time, why not get busy writing some variable handling functions of your own??

If anybody wants a function to selectively handle Form, Querystring, Cookies, Session, Application and Server variables then I have one...just mail me. It also has a parameter to run in DEBUG mode which will show you variables in all objects, their values and whether their names present a problem during conversion. It'll also flag those controls that can be set to arrays, etc.

Anyway, those that do feel inspired to get writing their own handlers, let me ask one thing.... Send me a copy of your finished function(s), this is pretty new stuff and I'm well open to being inspired by YOUR code.

Feel free to contact me with your feedback.

Enjoy!
http://www.aspwebpro.com/tutorials/asp/newwaytohandlevar.asp

DISPLAY DATA FROM DATABASE

Alright, you have your database connection established and now you want to display data from your database on your page. Easy enough. We'll take the same code that we left off with from our Open Database Connection Tutorial except we will change the database table name to myCustomers and build from there.

First, create a database with a table called myCustomers with the following fields and add some data:
Company - text field
Address - text field
City - text field
State - text field
Zipcode - number field

As a reminder, here is our open database connection code:

<% DIM objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=myCONNECTION.dsn" objConn.Open DIM mySQL mySQL = "SELECT * FROM myCustomers" DIM objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn %>

ASP Web Pro

Display data from database here.


Now, if you know that you only have one customer in your database to display, it is very simple. Just paste the below code into the body section of your page:



<% Response.Write objRS("Company") %>
<% Response.Write objRS("Address") %>
<% Response.Write objRS("City") %>
<% Response.Write objRS("State") %>
<% Response.Write objRS("Zipcode") %>



<% ' Don't forget to close your connection after you display your data. objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>

This will neatly display your customer's data on your page.
When displaying data from a database on your pages, it is a good idea to use tables to organize how the data will be displayed.

Now, ideally you will have more than one customer. If have multiple customers in your database, you need to do a little bit more



<% DO WHILE NOT objRS.EOF %> <% objRS.MoveNext Loop %>
<% Response.Write objRS("Company") %>
<% Response.Write objRS("Address") %>
<% Response.Write objRS("City") %>
<% Response.Write objRS("State") %>
<% Response.Write objRS("Zipcode") %>




<% ' Don't forget to close your connection after you display your data. objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>

In the first example, our page displays the first and only record returned by our mySQL statement. In this example, the <% DO WHILE NOT objRS.EOF %> and <% objRS.MoveNext...Loop %> code instructs our page to display the first record returned by our mySQL statement, move to the next record, and loop back and continue the table and display the next record until there are no more records left.

So what happens if you have 100 customers and it is just too much information to display on one page? You would probably just want to display the first 10 or 20 records on your page and include a next and previous link at the bottom so that you can scroll through your records more easily. We will get into that later, but for now we will let you absorb this. Congrats!

SEARCH ENGINES

Search Engines are a vital tool on the Internet. They provide web surfers with a way to find what they are looking for. Some of the most popular Search Engines are Excite, GoTo, Lycos, and MSN. There are literally 1,000's more of them, but they all serve the same purpose for the most part.

In order to use a Search Engine, all you do is type in a single keyword or phrase, click search and voila, you have a list of related web sites. Depending on your keyword and which particular search engine you use, you could have anywhere from 10 to 10,000,000 web sites in your results. Ok, you probably already knew that much. The real question is how do I get my web site to show up in those results and show up within the top 10 results. Well, as in many things in life, it all depends.

The first thing you need is a good web site. The second thing you need is to have an effective set of keyword and description META tags in your home page. These META tags must appear in this format:




and they must be located within the tags of your home page. Your keywords can either be a single word or a phrase and must be separated with a comma like this "asp, active server pages". Your description is a brief and to the point description of your web site.
Many Search Engines have advanced tools that rank your web site according to keyword relevance. In order for your keywords to be considered relevant, they should be used in your description META tag and also within the text of your home page. As a general rule, your keywords should appear at least 3 times within the text of your home page in order for them to be considered relevant. Be careful, though. If your keywords appear more than 8 times on your page, it may be considered spam by search engines and be banned from their listing service all together.

Now, you have your web site and your META tags. What next? Well, now you need to submit your web site to the search engines. You can do this manually on your own each month, which could potentially take hours of your own time or you can use a low cost search engine submission service like our SubmitME! program.

When you submit your web site to the major search engines, you want to use keywords that are as specific as possible. The reason for this is that search engines are big business these days. They charge literally $1,000's of dollars per month to huge corporations that want their web sites listed at the top of a given category and if you have a small business or personal web site, you simply cannot compete with that. For example, let's say you have a car dealership web site and you use "cars, trucks, sports utility vehicle" as your keywords. When a web surfer searches for the term cars, they will get a long list of car manufacturers like Chrysler, Ford, and Toyota. They will also get a long list of car rental companies like Avis, Budget, and Hertz because those companies are paying the top dollar to be listed first. You probably would not find your listing until about 300 sites later if you are lucky. Once you get past the top paying companies, most search engines list smaller web sites in random order so there is really not much you can do about that. Sometimes you may be listed within the top 100 and sometimes it will be the top 100,000. Sure, there are a couple of tricks that you can try that may help a little bit, but unless you are ready and willing to pay for it, you are better off looking for other options.

So how do we solve this dilemma? Narrow down your keywords. Instead of just using keywords like these: "cars, trucks, sports utility vehicle" try using specific brands or names like these: "Ford Bronco, Toyota Corolla" or narrow it down geographically like this: "Charlotte NC car dealerships, NC Ford dealerships", etc.

What else can I do? Nowadays, there are lots of smaller industry specific directories and search engines you can use. For example, if you are a manufacturing company, you can list your web site with the Thomas Register Directory of Manufacturers. There are also lots of geographically oriented search engines like www.uk.goto.com for the United Kingdom.

Search engines are a necessity for the survival of the Internet and its web sites in general. If you do not list your web site with search engines, the only people can find your site is either by word of mouth or by accident. That's a tough way to grow your web site, so get your web site and META tags together and start submitting!

http://www.aspwebpro.com/tutorials/internet/searchengines.asp

SEARCH ENGINES

Search Engines are a vital tool on the Internet. They provide web surfers with a way to find what they are looking for. Some of the most popular Search Engines are Excite, GoTo, Lycos, and MSN. There are literally 1,000's more of them, but they all serve the same purpose for the most part.

In order to use a Search Engine, all you do is type in a single keyword or phrase, click search and voila, you have a list of related web sites. Depending on your keyword and which particular search engine you use, you could have anywhere from 10 to 10,000,000 web sites in your results. Ok, you probably already knew that much. The real question is how do I get my web site to show up in those results and show up within the top 10 results. Well, as in many things in life, it all depends.

The first thing you need is a good web site. The second thing you need is to have an effective set of keyword and description META tags in your home page. These META tags must appear in this format:




and they must be located within the tags of your home page. Your keywords can either be a single word or a phrase and must be separated with a comma like this "asp, active server pages". Your description is a brief and to the point description of your web site.
Many Search Engines have advanced tools that rank your web site according to keyword relevance. In order for your keywords to be considered relevant, they should be used in your description META tag and also within the text of your home page. As a general rule, your keywords should appear at least 3 times within the text of your home page in order for them to be considered relevant. Be careful, though. If your keywords appear more than 8 times on your page, it may be considered spam by search engines and be banned from their listing service all together.

Now, you have your web site and your META tags. What next? Well, now you need to submit your web site to the search engines. You can do this manually on your own each month, which could potentially take hours of your own time or you can use a low cost search engine submission service like our SubmitME! program.

When you submit your web site to the major search engines, you want to use keywords that are as specific as possible. The reason for this is that search engines are big business these days. They charge literally $1,000's of dollars per month to huge corporations that want their web sites listed at the top of a given category and if you have a small business or personal web site, you simply cannot compete with that. For example, let's say you have a car dealership web site and you use "cars, trucks, sports utility vehicle" as your keywords. When a web surfer searches for the term cars, they will get a long list of car manufacturers like Chrysler, Ford, and Toyota. They will also get a long list of car rental companies like Avis, Budget, and Hertz because those companies are paying the top dollar to be listed first. You probably would not find your listing until about 300 sites later if you are lucky. Once you get past the top paying companies, most search engines list smaller web sites in random order so there is really not much you can do about that. Sometimes you may be listed within the top 100 and sometimes it will be the top 100,000. Sure, there are a couple of tricks that you can try that may help a little bit, but unless you are ready and willing to pay for it, you are better off looking for other options.

So how do we solve this dilemma? Narrow down your keywords. Instead of just using keywords like these: "cars, trucks, sports utility vehicle" try using specific brands or names like these: "Ford Bronco, Toyota Corolla" or narrow it down geographically like this: "Charlotte NC car dealerships, NC Ford dealerships", etc.

What else can I do? Nowadays, there are lots of smaller industry specific directories and search engines you can use. For example, if you are a manufacturing company, you can list your web site with the Thomas Register Directory of Manufacturers. There are also lots of geographically oriented search engines like www.uk.goto.com for the United Kingdom.

Search engines are a necessity for the survival of the Internet and its web sites in general. If you do not list your web site with search engines, the only people can find your site is either by word of mouth or by accident. That's a tough way to grow your web site, so get your web site and META tags together and start submitting!

http://www.aspwebpro.com/tutorials/internet/searchengines.asp

DISPLAY DATA FROM DATABASE

Alright, you have your database connection established and now you want to display data from your database on your page. Easy enough. We'll take the same code that we left off with from our Open Database Connection Tutorial except we will change the database table name to myCustomers and build from there.

First, create a database with a table called myCustomers with the following fields and add some data:
Company - text field
Address - text field
City - text field
State - text field
Zipcode - number field

As a reminder, here is our open database connection code:

<% DIM objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=myCONNECTION.dsn" objConn.Open DIM mySQL mySQL = "SELECT * FROM myCustomers" DIM objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn %>

ASP Web Pro

Display data from database here.


Now, if you know that you only have one customer in your database to display, it is very simple. Just paste the below code into the body section of your page:



<% Response.Write objRS("Company") %>
<% Response.Write objRS("Address") %>
<% Response.Write objRS("City") %>
<% Response.Write objRS("State") %>
<% Response.Write objRS("Zipcode") %>



<% ' Don't forget to close your connection after you display your data. objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>

This will neatly display your customer's data on your page.
When displaying data from a database on your pages, it is a good idea to use tables to organize how the data will be displayed.

Now, ideally you will have more than one customer. If have multiple customers in your database, you need to do a little bit more



<% DO WHILE NOT objRS.EOF %> <% objRS.MoveNext Loop %>
<% Response.Write objRS("Company") %>
<% Response.Write objRS("Address") %>
<% Response.Write objRS("City") %>
<% Response.Write objRS("State") %>
<% Response.Write objRS("Zipcode") %>




<% ' Don't forget to close your connection after you display your data. objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing %>

In the first example, our page displays the first and only record returned by our mySQL statement. In this example, the <% DO WHILE NOT objRS.EOF %> and <% objRS.MoveNext...Loop %> code instructs our page to display the first record returned by our mySQL statement, move to the next record, and loop back and continue the table and display the next record until there are no more records left.

So what happens if you have 100 customers and it is just too much information to display on one page? You would probably just want to display the first 10 or 20 records on your page and include a next and previous link at the bottom so that you can scroll through your records more easily. We will get into that later, but for now we will let you absorb this. Congrats!

SQL ADVANCED

OK, so you got through our SQL Basics Tutorial. Now, we are moving on to some more advanced SQL statements. As a refresher, here is our standard connection and recordset information, which shows you where your SQL will go.

<% DIM objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=myCONNECTION.dsn" objConn.Open DIM mySQL mySQL = "SELECT * FROM myTABLE" DIM objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn %>



Display data from database here.


Now, let's get to the good stuff. Here are some of the more advanced things you can do with your SQL statements.

mySQL = "SELECT Count(*) AS intTotal FROM tblInvoices"

This example counts the number of records contained in our intInvoices table.

mySQL = "SELECT SUM(Revenue) AS intTotal FROM tblInvoices"

This example sums a currency field called revenue from our intInvoices table. There are other commands you can use other than SUM in the same way. You can also replace SUM with AVG, MIN, or MAX to find the average, minimum, or maximum values. If you are really into statistical analysis, you can even use VARIANCE or STDDEV to return the variance or standard deviation values.

mySQL = "SELECT * FROM tblInvoices WHERE DueDate = # " & Date() & " # "

This example selects all of the records in our tblInvoices tables where the DueDate field equals todays date.

mySQL = "SELECT * FROM tblInvoices WHERE Type = ' " & strVariable & " ' "

This example selects all of the records in our tblInvoices tables where the Type field is equal to a string or text variable such as "Customer" that is entered on your ASP page.

mySQL = "SELECT * FROM tblInvoices WHERE Number = " & intVariable & " "

This example selects all of the records in our tblInvoices tables where the Number field is equal to an integer or numeric variable such as "100" that is entered on your ASP page.

These are only some of the more advanced SQL statements. We are still only scratching the surface here, but we will continue to add more advanced SQL statements to this page as time goes on so be sure to check back.

http://www.aspwebpro.com/tutorials/asp/sqladvanced.asp

SQL ADVANCED

OK, so you got through our SQL Basics Tutorial. Now, we are moving on to some more advanced SQL statements. As a refresher, here is our standard connection and recordset information, which shows you where your SQL will go.

<% DIM objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DSN=myCONNECTION.dsn" objConn.Open DIM mySQL mySQL = "SELECT * FROM myTABLE" DIM objRS Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open mySQL, objConn %>



Display data from database here.


Now, let's get to the good stuff. Here are some of the more advanced things you can do with your SQL statements.

mySQL = "SELECT Count(*) AS intTotal FROM tblInvoices"

This example counts the number of records contained in our intInvoices table.

mySQL = "SELECT SUM(Revenue) AS intTotal FROM tblInvoices"

This example sums a currency field called revenue from our intInvoices table. There are other commands you can use other than SUM in the same way. You can also replace SUM with AVG, MIN, or MAX to find the average, minimum, or maximum values. If you are really into statistical analysis, you can even use VARIANCE or STDDEV to return the variance or standard deviation values.

mySQL = "SELECT * FROM tblInvoices WHERE DueDate = # " & Date() & " # "

This example selects all of the records in our tblInvoices tables where the DueDate field equals todays date.

mySQL = "SELECT * FROM tblInvoices WHERE Type = ' " & strVariable & " ' "

This example selects all of the records in our tblInvoices tables where the Type field is equal to a string or text variable such as "Customer" that is entered on your ASP page.

mySQL = "SELECT * FROM tblInvoices WHERE Number = " & intVariable & " "

This example selects all of the records in our tblInvoices tables where the Number field is equal to an integer or numeric variable such as "100" that is entered on your ASP page.

These are only some of the more advanced SQL statements. We are still only scratching the surface here, but we will continue to add more advanced SQL statements to this page as time goes on so be sure to check back.

http://www.aspwebpro.com/tutorials/asp/sqladvanced.asp