%@ LANGUAGE = "VBScript" %>
<%
stage=request.querystring("stage")
update=request.querystring("update")
msg=""
'The customers details...NOT the delivery dets....
cfname=request.form("cfname")
clname=request.form("clname")
caddress1=request.form("caddress1")
caddress2=request.form("caddress2")
ccity=request.form("ccity")
cstate=request.form("cstate")
czip=request.form("czip")
ccountry=request.form("ccountry")
cphone=request.form("cphone")
cfax=request.form("cfax")
cemail=request.form("cemail")
cpass1=request.form("cpass1")
cpass2=request.form("cpass2")
if stage="register" then
' *******************************************************
' Validate user input
' *******************************************************
msg=""
if trim(cfname)="" then
msg=msg & "You need to enter a first name."
elseif len(cfname)>100 then
msg=msg & "Your first name is too long."
end if
if trim(clname)="" then
msg=msg & "
You need to enter a last name."
elseif len(clname)>100 then
msg=msg & "
Your last name is too long."
end if
if trim(caddress1)="" or trim(caddress2)="" then
msg=msg & "
You need to enter an address."
elseif len(caddress1)>255 or len(caddress1)>255 then
msg=msg & "
Your address is too long."
end if
if trim(ccity)="" then
msg=msg & "
You need to enter a city."
elseif len(ccity)>100 then
msg=msg & "
The city is too long."
end if
if trim(cstate)="" then
msg=msg & "
You need to enter a state."
elseif len(cstate)>100 then
msg=msg & "
Your state is too long."
end if
if trim(czip)="" then
msg=msg & "
You need to enter a zip."
elseif len(czip)>25 then
msg=msg & "
Your zip is too long."
end if
if trim(ccountry)="" then
msg=msg & "
You need to enter a country."
elseif len(ccountry)>100 then
msg=msg & "
Your country is too long."
end if
if trim(cphone)="" then
msg=msg & "
You need to enter a phone number."
elseif len(cphone)>30 then
msg=msg & "
Your phone number is too long."
end if
if len(cfax)>30 then
msg=msg & "
Your fax number is too long."
end if
if trim(cpass1)="" or trim(cpass2)="" then
msg=msg & "
You need to enter your password twice."
elseif trim(lcase(cpass1))<>trim(lcase(cpass2)) then
msg=msg & "
The two passwords entered do not match."
elseif len(cpass1)>10 or len(cpass2)>10 then
msg=msg & "
The passwords are too long."
end if
if trim(cemail)="" then
msg=msg & "
You need to enter an email address."
elseif len(cemail)>255 then
msg=msg & "
Your email address is too long."
else
'Check not already in DB
sql="select * from customers where email='" & valid_sql(cemail) & "'"
if session("custid")<>"" then
sql=sql & " and custid<>" & session("custid")
end if
set rsmail=db.execute(sql)
if not(rsmail.eof) then
msg= msg & "
The email address you entered is already registered"
end if
set rsmail=nothing
end if
if msg="" then
if update="True" then
'update the current user
sql="update customers set fname='" & valid_sql(cfname) & "',lname='" & valid_sql(clname) & "',email='" & valid_sql(cemail) & "',address1='" & valid_sql(caddress1) & "',address2='" & valid_sql(caddress2) & "',city='" & valid_sql(ccity) & "',zip='" & valid_sql(czip) & "',state='" & valid_sql(cstate) & "',country='" & valid_sql(ccountry) & "',pass='" & valid_sql(cpass1) & "',phone='" & valid_sql(cphone) & "'"
if cfax<>"" then
sql=sql & ",fax='" & valid_sql(cfax) & "'"
end if
sql=sql & " where custid=" & Session("custid")
db.execute(sql)
else
'add a new user
'To get custid back we have to do things a litle differently
Set rscust = Server.CreateObject("ADODB.RecordSet")
' Open the table
rscust.Open "customers", strConn, adOpenKeySet, adLockPessimistic, adCmdTable
' Add a new record
rscust.AddNew
rscust("fname") = cfname
rscust("lname") = clname
rscust("address1") = caddress1
rscust("address2") = caddress2
rscust("city") = ccity
rscust("state") = cstate
rscust("zip") = czip
rscust("country") = ccountry
rscust("phone") = cphone
if cfax<>"" then
rscust("fax") = cfax
end if
rscust("email") = cemail
rscust("pass") = cpass1
' Update the record
rscust.update
' Retrive the ID
Session("custid") = rscust("custid")
' Close the RecordSet
rscust.Close
end if
Set rscust = Nothing
response.redirect("deliver.asp")
end if
end if 'Stage
'Check if user is signed in
if session("custid")<>"" and stage<>"register" then
'retrieve the customres details from db
set rscus=db.execute("select * from customers where custid=" & session("custid"))
update=false
if not rscus.eof then
cfname=rscus("fname")
clname=rscus("lname")
caddress1=rscus("address1")
caddress2=rscus("address2")
ccity=rscus("city")
cstate=rscus("state")
czip=rscus("zip")
ccountry=rscus("country")
cphone=rscus("phone")
cfax=rscus("fax")
cemail=rscus("email")
cpass1=rscus("pass")
cpass2=rscus("pass")
update=true
end if
end if
%>
|
<% if session("custid")<>"" then %>
edit your profile
register as a customer
|