No, that's the problem I think!!

I can't work it out myself! I know that the username must be 
retrieved from somewhere because it works on the 'addCart' page but 
don't know how it is called.

The only other pages I can think of where it may have come from are 
the 'cart' page and the 'storefuncs' page. When a user registers, 
functiosn are called from the 'storefuncs' page which is the page 
that assigns a cookie. When th euser tries to purchase something, 
the 'cart' page is run and if they are already registered, they are 
taken to the 'addCart' page.

So, here's the 'cart' page:

======================================================================
==
<!-- #INCLUDE FILE="adovbs.inc" -->
<!-- #INCLUDE FILE="storefuncs.asp" -->
<%
' Get product ID
productID = TRIM( Request( "pid" ) )

' Get Login Information
username = TRIM( Request( "username" ) )
password = TRIM( Request( "password" ) )
register = TRIM( Request( "register" ) )
error = TRIM( Request( "error" ) )

'Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "accessDSN"

' Check for New Registration
IF register <> "" AND error = "" THEN
  addUser
END IF

' Get User ID
userID = checkpassword( username, password, Con )

IF userID > 0 THEN
   %>
   <!-- #INCLUDE FILE="addCart.asp" -->
   <% ELSE %>
      <!-- #INCLUDE FILE="register.asp" -->
   <%
END IF
%>

=====================================================================

and here's the 'storefuncs' page:

=====================================================================

<%
'==========================
'  Common Functions
'==========================
FUNCTION fixQuotes( theString )
  fixQuotes = REPLACE( theString, "'", "''" )
END FUNCTION


SUB addCookie( theName, theValue )
        Response.Cookies( theName ) = theValue
        Response.Cookies( theName ).Expires = "December 31, 2006"
        Response.Cookies( theName ).Path = "/"
        Response.Cookies( theName ).Secure = FALSE
END SUB



FUNCTION checkpassword( byVal username, byVal password, byRef Con )
  sqlString = "SELECT user_id FROM Users " &_
    "WHERE user_username='" & username & "' " &_
    "AND user_password='" & password & "'"
  SET RS = Con.Execute( sqlString )
  IF RS.EOF THEN 
    checkpassword = - 1
  ELSE
    checkpassword = RS( "user_id" )
    addCookie "username", username
        addCookie "password", password
  END IF
END FUNCTION


FUNCTION SELECTED( firstVal, secondVal )
  IF cSTR( firstVal ) = cSTR( secondVal ) THEN
    SELECTED = " SELECTED "
  ELSE
    SELECTED = ""
  END IF
END FUNCTION

SUB errorForm( errorMSG, backpage )
  %>
  <html>
  <head><title>Problem</title></head>
  <body bgcolor="#FFFFC6">

  <center>  
  <table width="500" border=1
    cellpadding=5 cellspacing=0>
  <tr>
    <td>
    <font face="Arial" size="3" color="darkblue"><b>
    There was a problem with the information you entered:
    </b></font>
    <font face="Arial" size="2" color="red"><b>
    <br><%=errorMSG%>
    </b></font>
    <br>
    <form method="post" action="<%=backpage%>">
    <input name="error" type="hidden" value="1">
    <% formFields %>
    <input type="submit" value="Return"> 
    </form>
    </td>
  </tr>
  </table>
  </center>

  </body>
  </html>
  <%
  Response.End
END SUB


SUB formFields
  FOR each item in Request.Form
  %>
  <input name="<%=item%>" type="hidden"
    value="<%=Server.HTMLEncode( Request( item ) )%>">
  <%
  NEXT
END SUB

'===========================
' Registration Functions
'===========================


SUB addUser
  ' Get Registration Fields
  newusername = TRIM( Request( "newusername" ) )
  newpassword = TRIM( Request( "newpassword" ) )
  title = TRIM( Request( "title" ) )
  firstname = TRIM( Request( "firstname" ) )
  surname = TRIM( Request( "surname" ) )
  gender = TRIM( Request( "gender" ) )
  email = TRIM( Request( "email" ) )
  telephone = TRIM( Request( "telephone" ) )
  street = TRIM( Request( "street" ) )
  city = TRIM( Request( "city" ) )
  county = TRIM( Request( "county" ) )
  postcode = TRIM( Request( "postcode" ) )
  country = TRIM( Request( "country" ) )
  cctype = TRIM( Request( "cctype" ) )
  ccnumber = TRIM( Request( "ccnumber" ) )
  ccexpires = TRIM( Request( "ccexpires" ) )
  ccname = TRIM( Request( "ccname" ) )
  
  ' Check For Required Fields
  backpage = Request.ServerVariables( "SCRIPT_NAME" )
  IF newusername = "" THEN
    errorForm "You must enter a username.", backpage
  END IF
  IF newpassword = "" THEN
    errorForm "You must enter a password.", backpage
  END IF
  IF title = "" THEN
    errorForm "You must enter your title, for example, 'Mr'. ", 
backpage
  END IF
  IF firstname = "" THEN
    errorForm "You must enter your firstname, for example, 'Tom'. ", 
backpage
  END IF
  IF surname = "" THEN
    errorForm "You must enter your surname, for example, 'Smith'. ", 
backpage
  END IF
  IF gender = "" THEN
    errorForm "You must specify your gender. ", backpage
  END IF
  IF email = "" THEN
    errorForm "You must enter your email address, for 
example, '[EMAIL PROTECTED]' ", backpage
  END IF
  IF telephone = "" THEN
    errorForm "You must enter your telephone number, for 
example, '0116 2510000 ", backpage
  END IF
  IF street = "" THEN
    errorForm "You must enter your street address, for example, '100 
High Street' ", backpage
  END IF
  IF city = "" THEN
    errorForm "You must enter your city, for example, 'Manchester' ", 
backpage
  END IF
  IF county = "" THEN
    errorForm "You must enter your county, for 
example, 'Yorkshire' ", backpage
  END IF
  IF postcode = "" THEN
    errorForm "You must enter your postcode, for example, 'E1 6RT' ", 
backpage
  END IF
  IF country = "" THEN
    errorForm "You must enter your country, for example, 'England' ", 
backpage
  END IF
  IF cctype = "" THEN
    errorForm "You must enter your method of payment, for 
example, 'Visa' ", backpage
  END IF
  IF ccnumber = "" THEN
    errorForm "You must enter your card number. ", backpage
  END IF
  IF ccexpires = "" THEN
    errorForm "You must enter the expiry date of your card, for 
example, '06/06' ", backpage
  END IF
  IF ccname = "" THEN
    errorForm "You must enter the name that appears on your card, for 
example, 'Mr J. Smith' ", backpage
  END IF

  ' Check for Necessary Field Values
  IF invalidEmail( email ) THEN
    errorForm "You did not enter a valid email address", backpage
  END IF

  ' Check whether username already registered
  IF alreadyUser( newusername ) THEN
    errorForm "The username you have entered is already in use. 
Please choose a different username.", backpage
  END IF

  ' Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "accessDSN"

  ' Add New User to Database
  sqlString = "INSERT INTO Users ( " &_
    "user_username, " &_
    "user_password, " &_
    "user_title, " &_
    "user_firstName, " &_
    "user_surname, " &_
    "user_gender, " &_
    "user_email, " &_
    "user_telephone, " &_
    "user_street, " &_
    "user_city, " &_
    "user_county, " &_
    "user_postcode, " &_
    "user_country, " &_
    "user_cctype, " &_
    "user_ccnumber, " &_
    "user_ccexpires, " &_
    "user_ccname" &_
    ") VALUES ( " &_
    " '" & fixQuotes( newusername ) & "', " &_
    " '" & fixQuotes( newpassword ) & "', " &_
    " '" & fixQuotes( title ) & "', " &_
    " '" & fixQuotes( firstname ) & "', " &_
    " '" & fixQuotes( surname ) & "', " &_
    " '" & fixQuotes( gender ) & "', " &_
    " '" & fixQuotes( email ) & "', " &_
    " '" & fixQuotes( telephone ) & "', " &_
    " '" & fixQuotes( street ) & "', " &_
    " '" & fixQuotes( city ) & "', " &_
    " '" & fixQuotes( county ) & "', " &_
    " '" & fixQuotes( postcode ) & "', " &_
    " '" & fixQuotes( country ) & "', " &_
    " '" & fixQuotes( cctype ) & "', " &_
    " '" & fixQuotes( ccnumber ) & "', " &_
    " '" & fixQuotes( ccexpires ) & "', " &_
    " '" & fixQuotes( ccname ) & "' " &_
    ")"

Con.Execute sqlString

  ' Use the new username and password
  username = newusername
  password = newpassword

  ' Add Cookies
  addCookie "username", username
  addCookie "password", password
END SUB


SUB updateUser
  ' Get Registration Fields
  street = TRIM( Request( "street" ) )
  city = TRIM( Request( "city" ) )
  county = TRIM( Request( "county" ) )
  postcode = TRIM( Request( "postcode" ) )
  country = TRIM( Request( "country" ) )
  cctype = TRIM( Request( "cctype" ) )
  ccnumber = TRIM( Request( "ccnumber" ) )
  ccexpires = TRIM( Request( "ccexpires" ) )
  ccname = TRIM( Request( "ccname" ) )
  userID = TRIM( Request( "user_id" ) )

  
  ' Check For Required Fields
  backpage = "doCheckout2.asp"
  IF street = "" THEN
    errorForm "You must enter your street address, for example, '100 
High Street'. ", backpage
  END IF
  IF city = "" THEN
    errorForm "You must enter your city, for 
example, 'Manchester'. ", backpage
  END IF
  IF county = "" THEN
    errorForm "You must enter your county, for 
example, 'Yorkshire'. ", backpage
  END IF
  IF postcode = "" THEN
    errorForm "You must enter your postcode, for example, 'E1 
6RT'. ", backpage
  END IF
  IF country = "" THEN
    errorForm "You must enter your country, for 
example, 'England'. ", backpage
  END IF
  IF cctype = "" THEN
    errorForm "You must enter your credit card type, for 
example, 'Visa'. ", backpage
  END IF
  IF ccnumber = "" THEN
    errorForm "You must enter your credit card number, (the 16 digit 
number on the front of your card). ", backpage
  END IF
  IF ccexpires = "" THEN
    errorForm "You must enter your credit card expiry date, for 
example, '07/07'. ", backpage
  END IF
  IF ccname = "" THEN
    errorForm "You must enter the name that appears on your credit 
card, 'Tom Smith'. ", backpage
  END IF

' Check for Necessary Field Values
  IF NOT validCCNumber( ccnumber ) THEN
    errorForm "You did not enter a valid credit card number", backpage
  END IF
  IF NOT isDATE( ccexpires ) THEN
    errorForm "You did not enter a valid credit card expiration 
date", backpage
  END IF

  ' Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "accessDSN"

  ' Update user information in the database
  sqlString = "UPDATE users SET " &_
    "user_street='" & fixQuotes( street ) & "', " &_
    "user_city='" & fixQuotes( city ) & "'," &_
    "user_county='" & fixQuotes( county ) & "'," &_
    "user_postcode='" & fixQuotes( postcode ) & "'," &_
    "user_ccnumber='" & ccnumber & "', " &_
    "user_cctype=" & cctype & ", " &_
    "user_ccexpires='" & ccexpires & "'," &_
    "user_ccname='" & fixQuotes( ccname ) & "' " &_
    "WHERE user_id=" & userID

response.Write(sqlString)
response.End
  Con.Execute sqlString
END SUB

FUNCTION invalidEmail( email )
  IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
    invalidEmail = TRUE
  ELSE
    invalidEmail = FALSE
  END IF
END FUNCTION

FUNCTION validCCNumber( ccnumber )
  ccnumber = CleanCCNum( ccnumber )
  IF ccnumber = "" THEN
    validCCNumber = FALSE
  ELSE
  isEven = False
  digits = ""        
  for i = Len( ccnumber ) To 1 Step -1
  if isEven Then
    digits = digits & CINT( MID( ccnumber, i, 1) ) * 2
  Else                
    digits = digits & CINT( MID( ccnumber, i, 1) )
  End If            
  isEven = (Not isEven)
  Next
  checkSum = 0
  For i = 1 To Len( digits) Step 1
    checkSum = checkSum + CINT( MID( digits, i, 1 ) )        
  Next
  validCCNumber = ( ( checkSum Mod 10) = 0 )
  END IF
End Function

FUNCTION alreadyUser( theUsername )
  sqlString = "SELECT user_username FROM users " &_
    "WHERE user_username='" & fixQuotes( theUsername ) & "'"
  SET RS = Con.Execute( sqlString )
  IF RS.EOF THEN
    alreadyUser = FALSE
  ELSE
    alreadyUser = TRUE
  END IF
  RS.Close
END FUNCTION



FUNCTION CleanCCNum( ccnumber )
  FOR i = 1 TO LEN( ccnumber )
    IF isNumeric( MID( ccnumber, i, 1 ) ) THEN
      CleanCCNum = CleanCCNum & MID( ccnumber, i, 1 )
    END IF
  NEXT
END FUNCTION


%>







 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspClassicAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to