Library sample chapters

Building an E-Commerce Shop Front

Introduction

This is a sample chapter from Professional Javascript.

In this chapter you will learn how to:

  • Build dynamic pages using server-side JScript v5 and ADO 2.1 to pull information from a SQL Server 7 database
  • Validate form based user input using client-side JavaScript
  • Persist state from page to page using cookies
  • Harness Active Server Page's transaction support via MTS (Microsoft Transaction Server) to process orders and store user orders in a database
  • Send e-mails using Microsoft's CDONTS (Collaboration Data Objects for Windows NT Server)

To work through this example, you will need access to Windows NT Server 4 or Windows 2000 with SQL7.0, JScript v5.0, IIS4 or 5, MTS, a simple mail server and a text editor installed upon it. Note also that where we have split lines of code onto two or more lines for clarity's sake, this has been marked with an underscore.

MusicMadOnline.com

Our imaginary client MusicMadOnline.com sells music compact discs and wants an online store to sell their products. They want customers to be able to browse their electronic shelves based on music genre. However they don't want their product lists or the categories to be hardwired in to the HTML pages although they do require the addition of new products and categories to be reflected automatically in the HTML pages.

Once the customer has selected their goods they must then be able to place an order online using a credit card for payment. Once an order has been accepted, the shipping department must be notified by e-mail of the customer's delivery address and items to be sent. The customer must also be notified by e-mail that their order has been accepted and will be delivered shortly.

Design aims

Businesses want to make money and can't afford to turn away customers. It's for this reason that the client-side part of MusicMadOnline.com has been designed to work on Internet Explorer and Netscape Navigator browsers version 3 and above. If we want to include Dynamic HTML effects particular to say IE4 or 5 then separate pages would most likely have to be written. Although it is possible to include support for different browsers in the same page, things can quickly get confusing.

On the server-side we have control of what version of JavaScript we use. Here I have used features available in JavaScript 1.2 and in particular those available in Microsoft's JScript Version 5.0 which comes with Internet Explorer 5.0 (IE5). If you don't want to install IE5 on your server than you can download the version 5.0 scripting engine from the Microsoft site (http://msdn.microsoft.com/scripting/jscript/default.htm) and install it on your server. Perhaps the best reason for upgrading to JScript v5 is its support of exception handling using the try…catch statement, but more on this later.

In anticipation of our online store being hugely popular we need to ensure it can cope with large numbers concurrent users and database transactions. It may be tempting to use something like Microsoft Access as our back end database, but as even Microsoft admit, Access won't cut it for high numbers of concurrent users. Instead I have used SQL Server 7 as the back-end database, though there are plenty of other high-end databases available which can provide the power we need.

SQL Server 7 also provides a greater level of sophistication, such as compiled stored procedures, which by modularizing our database code will make it more maintainable and as a bonus achieve greater scalability through being pre-compiled.

When dealing with large databases ensuring they don't become corrupted is always important. By this I mean that we don't want the situation where halfway through processing a customer's order we hit an unexpected error causing our application to drop out leaving the database in an inconsistent state. Either a transaction completes fully and the customer gets their goods or it fails and is rolled back completely and the customer is informed of this fact and where possible given information on why it happened and how they can proceed to complete their order. To help us with this objective we will make use of support for Microsoft Transaction Server transactions in ASP.

Comments

  1. 10 Apr 2006 at 18:53

    Is there an example anywhere of the customer log in?

     

    Thanks

     

    Frank

  2. 02 Mar 2004 at 12:40
    I am having the same issue.  I created the pages using MS SQL 8.0 and FP2002.  Did you ever get this problem resolved?  Please post if you found a solution.  
    Thanks
    Charity
  3. 27 Feb 2004 at 07:52

    I' trying to connect a simple Frontpage web (using the database wizard) to a database in sql servre 2000. I'm on a network supported by win server 2003 using win xp as clients. I've created login account in the "security" folder of sql server and gave it system admin rights. I also created a user account for that login to access the database and gave it "owner" rights. However everytime i try to write to the table in the database through the website (which is published to IIS on the network server) i get the message Database Results Error (invalid authorization specification). sql servre is configured to accept windows authentication only.


    Any help (hopefully more detailed) on this issue will be grtefully received as I'm a novice sql server user.

  4. 15 Jan 2004 at 10:16

    should be exactly the same!

  5. 04 Apr 2003 at 11:23
    is it possible to use microsoft SQL Server 2000 while going through your instructions and how much does it differ
  6. 06 Nov 2002 at 19:31

    hello, very good article. however since i am familiar with access, and learning asp. i was wondering if i could use access instead and what code should i use  in order to use msaccess instead of sql ...for this tutorial. Thanx a bundle

  7. 17 Jul 2002 at 20:01

    I am making 2 sites and one of them is asking people to use their credit cards to be validated and once that has done they can move onto the paying members section.


    PSN
    THE WORLD OF SOCCER

  8. 26 Mar 2002 at 13:41

    Got that working somehow dont ask me how but without password (good secruity) sql2000 pants! Anyway now have an issue adding items in the pop list or any list come to think of it doesnt allow items to be added this must be a cookie issue and i have checked to see them enabled locally. Can cookies be tested locally?


  9. 26 Mar 2002 at 10:20

    Found the following using google...




    A connection could not be established. Login failed.
    Reason: not associated with a trusted SQL Server connection


    After a few minutes of messing about and scratching my head, I remembered that while I was trying something else out I had previously set my default client connection type to TCP sockets, which of course don't support trusted connections! Oops. All went well once I had restored the default connection to named pipes. IOW, your SQL Server must support named pipes or multiprotocol for this method to work, which may require rerunning the setup application.




    Also, take a look at http://support.microsoft.com/default.aspx?scid=kb;en-us;Q307002

  10. 26 Mar 2002 at 09:39

    But having a hell of a time getting past this bloody error message


    Microsoft OLE DB Provider for SQL Server (0x80004005)
    Login failed for user 'MartinC'. Reason: Not associated with a trusted SQL Server connection.
    /musicmad/CategoryList.asp, line 12


    Have been through user admin changed everything to no avail anybody?


    Martin

  11. 01 Jan 1999 at 00:00

    This thread is for discussions of Building an E-Commerce Shop Front.

Leave a comment

Sign in or Join us (it's free).

Events coming up

  • Feb 25

    Mitcho's talk on Ubiquity and/or JetPack

    Cambridge, United States

    Our February 2010 JavaScript Meetup will be held on Thursday, February 25th at Microsoft Research Center located at One Memorial Drive in Cambridge. When you arrive security will direct you to the correct floor. There is also parking available at a cheap evening rate in the building. Parking is also free on the street in front of the building at 6 PM.At 6:30 PM our fellow member Mitcho (mitcho.com) will share his knowledge of Ubiquity and/or JetPack. I hear he is an awesome presenter.

We'd love to hear what you think! Submit ideas or give us feedback