Active Server Pages (ASP) : Show Records until a Certain date

July 10, 2006

This short tutorial will show you how to use a quick WHERE statement to filter your records so it only shows whilst the date column in the table is either greater or equal to the current day.

Prerequisites

Knowledge of using ASP pages For Dreamweaver uses you will need to feel comfortable using the Advanced view of a Recordset.

Obviously you will knowledge of using either Access or SQL server as your database.

Details

Create your Recordset as normal.

For the WHERE statement, use the below text, to show your records whilst the date column is greater or equal then the current day.

Change table to your table name and column to the column which contains your records date.

Using Access

WHERE (((table.column)>=Date()))

Using SQL server 2000

WHERE (((table.Column)>=getdate()))

If you are using Dreamweaver MX, you will need to change the Recordset to the Advanced view, and alter the WHERE statement to the text above.


Active Server Pages (ASP) : Submit a form when page loads

July 10, 2006

This v.short tutorial shows you how to submit a form when the page loads, so that the user does not have to click a button at all.

Prerequisites

Basic knowledge of HTML/ASP Comfortable typing code into page.

Details

Create your page.

Add a form, give it a name (fmform1)

Instead of adding the usual Textfields, menus etc place Hidden fields to capture all the data you which to include in your form. i.e value=

If this is a simple form to second page, then give the form the destination page as normal, if it is an Insert or Update script then include your usual code.

Find the BODY tag for your page and add this code onLoad=”document.fmform1.submit()”

And there you have it, you form will run when the page loads, then move onto your destination page with hardly a pause, and the user will be none the wise.


Active Server Pages (ASP) : Set LocalID to UK

July 10, 2006

This small piece of code is used to set the locality ID to UK to ensure dates and other regional data is set correctly. produces dates as dd/mm/yyyy if you enter now()

Prerequisites

You simply need to have some experience of ASP pages, and feel comfortable entering hand code.

Details

Add the following code to your ASP section on the web pages you wish to use it

‘Sets the Locale ID session property to UK region
Session.LCID = 2057


Active Server Pages (ASP) : Convert a Date to ISO format

July 10, 2006

This short tutorial will show you how to take any date, either in a database or passed in your page, and split it up and reassemble in the ISO format.

This can be very helpful in querying against your database, as it does not require the database to be set to your localised language and thus Date format, I have also found Access plays a lot nicer when the Date is in ISO format.

Details

I have included two examples, the first is using a recordset value, and needs to be placed around the output, not in the top of the page if you have multiple records, as it will set all values for every record to the same value.

Dim ISODOB
DOBDate = DatePart(“d”, rsreportdetails(“ClientDOB”))
If DOBDate
ISODOB

This example took the column ClientDOB from the recordset rsreportdetails, and split it up, into Date, Month and Year, then reassembled it in the ISO format of YYYY-MM-DD. Using displays the output on the page.

My second example uses a Form value or value passed in the URL.

Dim ISOStartDate
varSDate = DatePart(“d”, Request(“StartDate”))
If varSDate

again we are splitting up the date and reassembling in the ISO format. You would then in your recordset use ISOStartDate as the value of the definition for checking against the database.


Dreamweaver : Create a Login page and Userdetails table

July 10, 2006

This Tutorial walks you through setting up a database table to house your Users login details, and set up a Login page within Dreamweaver.

It also included details on Restricting access to pages within your site to only those who have logged in via your Login page.

Prerequisites

You will need either PWS or IIS running on your computer to run the ASP pages.

This Tutorial expects some experience in developing ASP pages in Dreamweaver MX, although each part will be walked through point by point, so you really just need to feel comfortable using Dreamweaver MX (trial version can be downloaded from macromedia.com)

You will need to know how to create a datebase and add tables.

Details

  1. Create a new database in your choice of flavour (Access, SQL Server, MySQL)
  2. Create a new table, name it user_logins
  3. Change to design view.
  4. Create a column for AccountID, UserName, UserPassword and any others you may wish, i.e UserReal, UserEmail etc, CreatedDate but the first 3 are a minimum

Types for each column

  • AccountID (Access= Autonumber, SQL server = int, Identity, not for repeating)<–primary key
  • UserName (Access=text, SQL server = varchar (50) )
  • UserPassword (Access=text, SQL server = varchar (50) )
  • If using Created Date (Access=date, default = now() SQL server=Date/time, default=getdate() )

Save your table

Open Dreamweaver

  • Create a new ASP page.
  • Add a form tag (call it something like fmlogin)
  • Add 2 text fields, call 1=Username, 2=Userpassword
  • Add a Submit button
  • In the Application palette…Server Behaviours…Authenticate User…Login user
  • Choose your connection (this will need setting up before hand to either talk to an ODBC or DSN-less connection)
  • Select the user_logins table.
  • Dreamweaver would have already entered the Form fields for Username and Password, you will need to tell it which columns in the database are for Username and Password.
  • Enter the page you wish it to go to if the login is successful, and the one if the login fails.

You have finished your login page.

If you only want people who have logged in to see them, you will need to restrict each page you are protecting with this login.

Open each page you want to protect …. In the Application pallete…Server Behaviours…Authenticate User…Restrict access to page.

Enter the page to go to if someone tries to access the page without logging in, or if their session has timed out.


Dreamweaver : Dynamically redirect your Login page

July 10, 2006

This Tutorial enables you to use 1 login page for sites with areas restricted to certain users.

By using a column in your database, and a small piece of coding to add to the login script, you can move your users dynamically to the appropriate folder for their access level.

Prerequisites

You need to be comfortable using Dreamweaver MX, and be able to follow basic instructions in adding code to the prebuilt dreamweaver page.

You will need a database, either Access or SQL server and be comfortable designing the database and tables required.

Details

Create a table in your database with a minimum of 4 fields,

ID for the record, Username, UserPassword and AccessLevel

Create your login page as normal;

  • design your page
  • add a form and enter two field box for the Username and Password.

In Application/Server behaviours/User Authentication select Login user.
Set the behaviour up by choosing the correct connection, table and marrying up the form fields to the database fields.

Enter your failed and successful pages as normal, and make sure you select to use Access Level as well as Username and Password. Use the column AccessLevel in the database for the Access level.

Save your page.

Change to Code view.

Your login code will be at the top of the page, move down the code until you find:

If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then ‘ username and password match – this is a valid user

Move down a little until this line Session(“MM_UserAuthorization”) = “” End If

Enter a break return and paste this code below that line:

‘ redirect user based on Access level
If Session(“MM_UserAuthorization”) = “category1″ Then
MM_redirectLoginSuccess = “folder1/”
ElseIf Session(“MM_UserAuthorization”) = “category2″ Then
MM_redirectLoginSuccess = “folder2/”
Else MM_redirectLoginSuccess = “folder3/”
End If

Change the category1, category2 to the settings you have in the column AccessLevel in your user details table.

Change the folder for folder1, folder2 to respective folders for each category.

The final folder3 is for the default folder or file to move to if the person exists in the table, but a Access Level has not been found.

If you always require an Access Level to be found, then set this last If to the failed page. You can add more ElseIf statements for extra categories.

Don’t forget to use the Restrict Access to page behaviour on each page that requires a login, so if for someone does get by, they will automatically be moved to your failed page, and not gain access simply by entering a URL.