SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Classic Asp probs

    Hi all
    I have been giving been given an asp application. I have to create files new_customer_reg.asp. Its doing my head in at the moment. I think the problem starts when i call AddNewCustomer function it mite be the strFCartRef not sure. If anyone could point me in the right direction that would be great.



    new_customer_reg.asp

    <%@Language=VBScript %>
    <% Option Explicit
    '*******************************************
    '*******************************************

    'PROECDURES **************************************
    %>
    <!--#include file="app_constants.asp" -->
    <!--#include file="eca_functions.asp" -->
    <%

    'MAIN **************************************
    Dim arrCustomerData()
    Dim strName, strFame, strWelcome
    Dim intCustRef
    Dim blnIsCustomer, blnShopBasket

    'test if the user has a cookie from a previous visit
    If Len(Request.Cookies("AandBPans")("Cart")) > 0 Then
    'test the customer exists
    blnIsCustomer = IsValidCustomer(Request.Cookies("AandBPans")("Cust"))

    If blnIsCustomer Then
    'OK, save customer ref
    intCustRef = CInt(Request.Cookies("AandBPans")("Cust"))
    Session.Contents("custID") = intCustRef

    'get the customer details rom the data file
    GetCustomerData arrCustomerData, intCustRef

    'save the customer's name
    strName = arrCustomerData(2)
    strFame = arrCustomerData(3)
    Session.Contents("CustName") = strName & " " & strFame
    strWelcome = "<h2>Welcome " & strName & " " & strFame & "</h2>"

    'test the shopping cart exists
    blnShopBasket = IsValidBasket(Request.Cookies("AandBPans")("Cart"))
    If blnShopBasket Then
    'yes, so save it
    Session.Contents("ShopCart") = Request.Cookies("AandBPans")("Cart")
    Else
    'no such basket file
    Session.Contents("ShopCart") = 0
    End If
    Else
    'no cart reference and no customer ID, so reset values
    Session.Contents("ShopCart") = 0
    Session.Contents("custID") = 0
    strWelcome = "<h2>Welcome</h2>"

    End If
    End If

    'set default value of Session variable IsAuthenticated
    'this section should be added if the global.asa file is not used
    'If Session.Contents("IsAuthenticated") <> 1 Then
    'Session.Contents("IsAuthenticated") = 0
    'End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>AandB Home Page</title>
    <link rel="STYLESHEET" type="text/css" href="abpans.css">
    </head>
    <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0">
    <img src="images/cook_shop.gif" alt="A and B Pans" width="500" height="60" border="0">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <!-- navigation cell -->
    <td width="25%" rowspan="3" valign="top" nowrap>
    <!--#include file="nav_menu_inc.asp"-->
    </td>
    <!-- main cell -->
    <td valign="top">
    <p>
    <% Response.Write ("<!-- cart=" & Session.Contents("ShopCart") & ", cust=" & Session.Contents("custID") & " authenticated=" & Session.Contents("IsAuthenticated") & " -->") %>
    <%= strWelcome %></p>
    <p>&nbsp;</p>
    <table width="70%" border="1" cellpadding="2" summary="Registration form">


    <form name="registeruser" id="registeruser" action="register_procede.asp" method="post" >

    <caption align="top">
    Required details
    </caption>
    <tr>
    <th width="40%" scope="col"><div align="center"><strong>First Name</strong></div></th>
    <th width="60%" scope="col"><div align="center">
    <input name="strFNam" type="text" id="strFNam" size="22"/>
    </div></th>
    </tr>
    <tr>
    <td><div align="center"><strong>Family Name</strong></div></td>
    <td><label>
    <div align="center">
    <input name="strFFam" type="text" id="strFFam" size="22">
    </div>
    </label></td>
    </tr>
    <tr>
    <td><div align="center"><strong>Password</strong></div></td>
    <td><div align="center">
    <label>
    <input name="strFPwd" type="password" id="strFPwd" size="22">
    </label>
    </div></td>
    </tr>
    <tr>
    <td><div align="center"><strong>Email</strong></div></td>
    <td><div align="center">
    <label>
    <input name="strFEmail" type="text" id="strFEmail" size="22">
    </label>
    </div></td>
    </tr>
    <tr>
    <td><div align="center"><strong>Contact Number</strong></div></td>
    <td><div align="center">
    <input name="strFPhon" type="text" id="strFPhon" size="22">
    </div></td>
    </tr>
    <tr>
    <td><div align="center"><strong>Home Address</strong></div></td>
    <td rowspan="4" align="center" valign="top"><div align="center">
    <textarea rows="5" cols="20" name="strFAddr" id="strFAddr"></textarea>
    </div></td>
    </tr>
    <tr>
    <td><%
    'when this page loads for the first time, Session("Errors") is set to '0' (False) this is then updated if a postback is performed

    if Session("Errors")=0 then
    response.write "Please fill out the form"
    else
    'ERRORS WERE MADE SO LIST THEM IN THE REST OF THE TABLE
    'reset our error counter
    Session("Errors")="0"
    response.write "<br />I am afraid that there <br /> " & "were errors in you form submission <br />" & "Please refer to this list to discover the problembr>"
    response.write"<TABLE border=0 width=' 400' align='center'>"

    'THESE SESSION VARIABLES ARE SET IN THE SECOND PAGE
    ' IF THERE WERE ERRORS 'VALUE IS "F"
    If Session("badstrFNam") = "T" then
    Response.write "<TR><TD><p class='errormes'>The First Name field must be completed.</p>"
    Response.write "</TD></TR>"
    Session("badstrFNam")="F"
    End If


    If Session("badstrFFam") = "T" then
    Response.write "<TR><TD><p class='errormes'>The Last Name field must be completed. </p>"
    Response.write "</TD></TR>"
    Session("badstrFFam")="F"
    End If

    If Session("badstrFPwd") = "T" then
    Response.write "<TR><TD><p class='errormes'>Please enter a Password.</p>"
    Response.write "</TD></TR>"
    Session("badstrFPwd")="F"
    End If

    If Session("badstrFEmail") = "T" then
    Response.write "<TR><TD><p class='errormes'>Please enter a valid Email address.</p>"
    Response.write "</TD></TR>"
    Session("badstrFEmail")="F"
    End If

    If Session("badstrFPhon") = "T" then
    Response.write "<TR><TD><p class='errormes'>Please enter a Phone number.</p>"
    Response.write "</TD></TR>"
    Session("badstrFPhon")="F"
    End If

    If Session("badstrFAddr") = "T" then
    Response.write "<TR><TD><p class='errormes'>Please Enter your home address</p>"
    Response.write "</TD></TR>"
    Session("badstrFAddr")="F"
    End If


    'END THE ERRORS TABLE
    response.write "</TD></TR></TABLE>"
    End If
    %></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><div align="center"></div></td>
    <td><div align="center">
    <input type="submit" value="Submit"/>
    </div> </tr>
    </table>


    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2" valign="top">&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>


    register_procedure.asp


    <%@Language=VBScript %>
    <% Option Explicit
    '*******************************************
    'Application: A and B Pots and Pans - on-line sales application
    'Author: Nick Heap
    'Date: 22 June 2004
    'Version: 1.1
    'Page: ab_home.asp
    'QueryString: None
    'Form: None
    'Purpose: application's home page
    '*******************************************

    'PROECDURES **************************************
    %>
    <!--#include file="eca_functions.asp" -->
    <!--#include file="app_constants.asp" -->
    <%

    'MAIN **************************************
    Dim arrCustomerData()
    Dim strName, strFame, strWelcome
    Dim intCustRef
    Dim blnIsCustomer, blnShopBasket

    'test if the user has a cookie from a previous visit
    If Len(Request.Cookies("AandBPans")("Cart")) > 0 Then
    'test the customer exists
    blnIsCustomer = IsValidCustomer(Request.Cookies("AandBPans")("Cust"))

    If blnIsCustomer Then
    'OK, save customer ref
    intCustRef = CInt(Request.Cookies("AandBPans")("Cust"))
    Session.Contents("custID") = intCustRef

    'get the customer details rom the data file
    GetCustomerData arrCustomerData, intCustRef

    'save the customer's name
    strName = arrCustomerData(2)
    strFame = arrCustomerData(3)
    Session.Contents("CustName") = strName & " " & strFame
    strWelcome = "<h2>Welcome " & strName & " " & strFame & "</h2>"

    'test the shopping cart exists
    blnShopBasket = IsValidBasket(Request.Cookies("AandBPans")("Cart"))
    If blnShopBasket Then
    'yes, so save it
    Session.Contents("ShopCart") = Request.Cookies("AandBPans")("Cart")
    Else
    'no such basket file
    Session.Contents("ShopCart") = 0
    End If
    Else
    'no cart reference and no customer ID, so reset values
    Session.Contents("ShopCart") = 0
    Session.Contents("custID") = 0
    strWelcome = "<h2>Welcome</h2>"

    End If
    End If

    'set default value of Session variable IsAuthenticated
    'this section should be added if the global.asa file is not used
    'If Session.Contents("IsAuthenticated") <> 1 Then
    'Session.Contents("IsAuthenticated") = 0
    'End If
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>AandB Home Page</title>
    <link rel="STYLESHEET" type="text/css" href="abpans.css">
    </head>
    <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0">
    <img src="images/cook_shop.gif" alt="A and B Pans" width="500" height="60" border="0">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <!-- navigation cell -->
    <td width="25%" rowspan="3" valign="top" nowrap>
    <!--#include file="nav_menu_inc.asp"-->
    </td>
    <!-- main cell -->
    <td valign="top">
    <p>
    <% Response.Write ("<!-- cart=" & Session.Contents("ShopCart") & ", cust=" & Session.Contents("custID") & " authenticated=" & Session.Contents("IsAuthenticated") & " -->") %>
    <%= strWelcome %></p>
    <p>&nbsp;</p>
    <%

    'declare values that are used in this form but have not been posted from previous web page
    dim strFCartRef, strFNam, strFFam, strFPwd, strFEmail, strFPhon, strFAddr
    dim formvalidation
    dim username, password

    Session("strFNam")=Request("strFNam")
    Session("strFFam")=Request("strFFam")
    Session("strFPwd")=Request("strFPwd")
    Session("strFEmail")=Request("strFEmail")
    Session("strFPhon")=Request("StrFPhon")
    Session("strFAddr")=Request("StrFAddr")

    'Check to see if First name text Box is not empty nor does it contain excessive characters
    if not len(Request("strFNam")) > 0 then
    Session("badstrFNam")="T"
    Session("Errors")=Session("Errors") + 1
    end if


    'check to see if Family name text box is empty or if there are excessive characters:
    if not len(Request("strFFam")) > 0 then
    Session("badstrFFam")="T"
    Session("Errors")=Session("Errors") + 1
    end if


    'Password section, firstly we have to check if both passwords match:

    If not len(Request("strFPwd")) > 0 then
    Session("badstrFPwd")="T"
    Session("Errors")=Session("Errors") + 1
    end if

    'Email address Validation

    if not len(Request("strFEmail")) > 0 then
    Session("badstrFEmail")="T"
    Session("Errors")=Session("Errors") + 1
    end if

    if not len(Request("strFPhon")) > 0 then
    Session("badstrFPhon")="T"
    Session("Errors")=Session("Errors") + 1
    end if

    if not len(Request("strFAddr")) > 0 then
    Session("badstrFAddr")="T"
    Session("Errors")=Session("Errors") + 1
    end if

    'there were errors, so send back to form
    if Session("Errors") > 0 then
    response.redirect "new_customer_reg.asp"
    'there were no errors, so do the update to the database and redirect to a thank you page
    else
    formvalidation = True
    AddNewCustomer strFCartRef, Session("strFNam"), Session("strFFam"), Session("strFPwd"), Session("strFEmail"), Session("strFPhon"), Session("strFAddr")
    End if

    %>
    </p>
    <p>&nbsp;


    <%
    If formvalidation = True then
    response.write("<br /><br /><br /><br /><br /><br />Thank you for registering your user id is: ")%>
    <%

    username = Request("strFEmail")
    response.write(username)
    End If
    %></p>
    <p>
    <%
    If formvalidation = True then
    response.write("<br />Your Password is: ")%>
    <%

    password = Request("strFPwd")
    response.write(password & "<p>Please keep a copy or remember this password</p> <p>You can now <a href='customer_login.asp' class='blueLink'>Login</a></p>")
    End If
    %>


    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2" valign="top">&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>


    Functions

    '**************************************
    Function GetAllCustomers(arrCusts, strDataFileName)
    'Purpose: retrieve all customer details into an array
    'inputs: none
    'outputs: arrCusts - returns retrieved data to caller
    'return: 0 or number of records found
    '**************************************
    Const FORREADING = 1

    'declare local objects
    Dim objFSO, objTS
    'declare local variables
    Dim strCustomerData
    Dim intRecCount, intRecordLine,intLinesPerRecord

    'set the name of the data file in the servers URI space
    strCustomerData = Server.MapPath("data/" & strDataFileName & ".txt")

    'create the FileSystemObject and TextStream objects
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTS = objFSO.OpenTextFile(strCustomerData, FORREADING)

    'set the array index variable to zero for the first record
    intRecCount=0

    'loop through each record of the file for the customer details
    Do While Not objTS.AtEndOfStream
    'remember that only the last dimension of the array can change size
    ReDim Preserve arrCusts(8,intRecCount)
    arrCusts(0,intRecCount) = objTS.ReadLine 'Customer ID
    arrCusts(1,intRecCount) = objTS.ReadLine 'shopping basket
    arrCusts(2,intRecCount) = objTS.ReadLine 'firstname
    arrCusts(3,intRecCount) = objTS.ReadLine 'family name
    arrCusts(4,intRecCount) = objTS.ReadLine 'pwd
    arrCusts(5,intRecCount) = objTS.ReadLine 'email
    arrCusts(6,intRecCount) = objTS.ReadLine 'phone
    arrCusts(7,intRecCount) = objTS.ReadLine 'address
    arrCusts(8,intRecCount) = objTS.ReadLine 'date of previous visit
    'increment the record count
    intRecCount=intRecCount+1
    Loop

    objTS.Close 'close file
    Set objTS = Nothing 'clear local object
    Set objFSO = Nothing 'clear local object

    'determine the return value
    If intRecCount = 0 Then
    GetAllCustomers = -1
    Else
    GetAllCustomers = intRecCount
    End If
    End Function

    '**************************************
    Function AddNewCustomer(strFCartRef, strFNam, strFFam, strFPwd, strFEmail, strFPhon, strFAddr)
    'Purpose: writes a new customer to the data file
    'inputs: strFCartRef - shopping basket ref number
    ' strFNam - first name
    ' strFFam - family name
    ' strFEmail - email address
    ' strFPwd - password
    ' strFPhon - phone number
    ' strFAddr - postal address
    'outputs: None
    'return: new customer ID number or 0
    'notes: requires 'app_constants.asp'
    '**************************************
    Const OVERWRITE = True

    'declare local variables
    Dim arrFCustomers()
    Dim intFHaveCustomers, intFCustIndex, intFNewCustID
    Dim strFToday

    'read all the customer records
    intFHaveCustomers = GetAllCustomers(arrFCustomers, CUSTFILE)

    'add the new data to the array
    If intFHaveCustomers > 0 Then
    'get the next customer ID number to use
    intFNewCustID = GetNextCustomerID()
    intFCustIndex = intFHaveCustomers
    ReDim Preserve arrFCustomers(8, intFCustIndex)
    'add the new record to end of the array
    arrFCustomers(0,intFCustIndex) = intFNewCustID 'cust ID number
    arrFCustomers(1,intFCustIndex) = strFCartRef 'shopping basket
    arrFCustomers(2,intFCustIndex) = strFNam 'firstname
    arrFCustomers(3,intFCustIndex) = strFFam 'family name
    arrFCustomers(4,intFCustIndex) = strFPwd 'pwd
    arrFCustomers(5,intFCustIndex) = strFEmail 'email
    arrFCustomers(6,intFCustIndex) = strFPhon 'phone
    arrFCustomers(7,intFCustIndex) = strFAddr 'address
    'format today's date
    strFToday = Day(Now) & "-" & MonthName(Month(Now),True) & "-" & Year(Now)
    arrFCustomers(8,intFCustIndex) = strFToday 'date of today's visit
    'update complete so set return flag
    AddNewCustomer = intFNewCustID
    Else
    'set return to flag error
    AddNewCustomer = 0
    End If

    'write the new data to customer file
    UpdateCustomerFile arrFCustomers, CUSTFILE
    End Function

    '**************************************

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,565
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Hi, this belongs in the ASP forum don't you think?
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  3. #3
    SitePoint Addict
    Join Date
    Jan 2007
    Posts
    344
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem starts when i call AddNewCustomer function it mite be the strFCartRef not sure. If anyone could point me in the right direction that would be great.
    What specifically are the symptoms, current results, problems and desired results besides "it don't work"? You need to fully describe the problem. No one is going to read several screenfuls of code without a reason.

    That is a *lot* of code and not particularly well formatted. Try using the code formatting tags.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •