Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing user's to update their details.

Status
Not open for further replies.

JOEJOETHEJOEY

IS-IT--Management
Aug 11, 2003
4
GB
Hi there,

I've been struggling with the code below to perform what I need to do.

Firstly, I need the page to find out whether the user is logged into the website already by looking for the username and password in the cache.

- If yes, then the user's details will be displayed on the page ready for updating.

- If not, and the user has already registered before, but isn't logged in, then the user can enter his username and password and click on update and the page will show all his details from the database ready for updating.

- If not, and the user "hasn't" registered before, then the fields will be empty and the details entered will be stored into the database.


I have managed to get the page to display the user's details when they have logged in or when they enter their username and password into the page, but I can't get it to:

- Update these details.

- Add new user's details to the database.


The CODE is as shown here "mypage.asp" :

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

<!-- #INCLUDE FILE=&quot;adovbs.inc&quot; -->
<!-- #INCLUDE FILE=&quot;storefuncs.asp&quot; -->

<%
'Get User ID
userID = TRIM( Request( &quot;uid&quot; ) )

'Get Login Info
login = TRIM( Request( &quot;login&quot; ) )
IF login <> &quot;&quot; THEN
username = TRIM( Request( &quot;username&quot; ) )
password = TRIM( Request( &quot;password&quot; ) )
ELSE
username = TRIM( Request( &quot;nusername&quot; ) )
password = TRIM( Request( &quot;npassword&quot; ) )
END IF

mypage = TRIM( Request( &quot;myypage&quot; ) )
error = TRIM( Request( &quot;error&quot; ) )
register = TRIM( Request( &quot;register&quot; ) )
IF username = &quot;&quot; THEN
username = request.cookies(&quot;username&quot;)
password = request.Cookies(&quot;password&quot;)
END IF


' Open Database Connection
Set Con = Server.CreateObject( &quot;ADODB.Connection&quot; )
Con.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & Server.Mappath(&quot;storeDB.mdb&quot;)& &quot;; Jet OLEDB:Database Password=&quot;


' Check for update code
IF mypage <> &quot;&quot; AND error = &quot;&quot; THEN
updateUser
END IF

IF register <> &quot;&quot; AND error = &quot;&quot; THEN
adduser
END IF


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

' See if user exists in database, or if info was actually passed
IF userID > 0 THEN
SET RS = Con.Execute(&quot;SELECT * FROM Users WHERE user_ID = &quot;&userID)

'Set string values with existing settings
nusername = RS(&quot;user_username&quot;)
npassword = RS(&quot;user_password&quot;)
email = RS(&quot;user_email&quot;)
street = RS(&quot;user_street&quot;)
town = RS(&quot;user_town&quot;)
county = RS(&quot;user_county&quot;)
postcode = RS(&quot;user_postcode&quot;)
cctype = RS(&quot;user_cctype&quot;)
ccnumber = RS(&quot;user_ccnumber&quot;)
ccexpires = RS(&quot;user_ccexpires&quot;)
ccname = RS(&quot;user_ccname&quot;)
END IF
%>

<html>
<head><title>My Account Page</title></head>
<body bgcolor=&quot;white&quot;>

<center>

<table width=&quot;500&quot; border=0
cellpadding=4 cellspacing=0>
<tr>
<td bgcolor=&quot;darkgreen&quot;>
<font color=&quot;white&quot; face=&quot;Arial&quot;>
<b>Update</b>
</font>
</td>
</tr>

<tr>
<td>
<form method=&quot;post&quot; action=&quot;<%=submitpage%>&quot;>
<input name=&quot;mypage&quot; type=&quot;hidden&quot; value=&quot;1&quot;>
<input name=&quot;pid&quot; type=&quot;hidden&quot; value=&quot;<%=productID%>&quot;>
<font face=&quot;Arial&quot; size=&quot;2&quot;>
Please make any changes to your details and click on &quot;Update&quot; to submit.
</font>
<font face=&quot;Arial&quot; size=&quot;2&quot; color=&quot;darkgreen&quot;>
<p><B>Login Information:</B>
</font>
<font face=&quot;Courier&quot; size=&quot;2&quot;>
<br><B>Username:</B>
<input name=&quot;nusername&quot; size=&quot;20&quot; maxlength=&quot;20&quot;
value=&quot;<%=nusername%>&quot;>
<br><B>Password:</B>
<input name=&quot;npassword&quot; size=&quot;20&quot; maxlength=&quot;20&quot;
value=&quot;<%=npassword%>&quot;>
<br><B>Email address:</B>
<input name=&quot;email&quot; size=&quot;30&quot; maxlength=&quot;75&quot;
value=&quot;<%=email%>&quot;>
</font>
<font face=&quot;Arial&quot; size=&quot;2&quot; color=&quot;darkgreen&quot;>
<p><B>Address Information:</B>
</font>
<font face=&quot;Courier&quot; size=&quot;2&quot;>
<br><B>Street:</B>
<input name=&quot;street&quot; size=&quot;20&quot; maxlength=&quot;50&quot;
value=&quot;<%=street%>&quot;>
<br><B>Town:</B>
<input name=&quot;town&quot; size=&quot;20&quot; maxlength=&quot;50&quot;
value=&quot;<%=town%>&quot;>
<br><B>County:</B>
<input name=&quot;county&quot; size=&quot;20&quot; maxlength=&quot;50&quot;
value=&quot;<%=county%>&quot;>
<br><B>Postcode:</B>
<input name=&quot;postcode&quot; size=&quot;20&quot; maxlength=&quot;10&quot;
value=&quot;<%=postcode%>&quot;>
</font>
<font face=&quot;Arial&quot; size=&quot;2&quot; color=&quot;darkgreen&quot;>
<p><B>Payment Information:</B>
</font>
<font face=&quot;Courier&quot; size=&quot;2&quot;>
<br><B>type of credit card:</B>
<select name=&quot;cctype&quot;>
<option value=&quot;1&quot;
<%=SELECTED( cctype, &quot;1&quot; )%> > VISA
<option value=&quot;2&quot;
<%=SELECTED( cctype, &quot;2&quot; )%> > MasterCard
</select>
<br><B>Credit Card Number:</B>
<input name=&quot;ccnumber&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;<%=ccnumber%>&quot;>
<br><B>Credit Card Expiry Date:</B>
<input name=&quot;ccexpires&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;<%=ccexpires%>&quot;>
<br><B>Name on card:</B>
<input name=&quot;ccname&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;<%=ccname%>&quot;>
<br>
<br>
<input type=&quot;submit&quot; value=&quot;Update&quot;>
</font>
</FORM>

</td>
</tr>

</TABLE>

</center>

</body>
</html>

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



The addUser and updateUser functions are contained in the &quot;storefuncs.asp&quot; page with this code:

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

SUB addUser
' Get Registration Fields
nusername = TRIM( Request( &quot;nusername&quot; ) )
npassword = TRIM( Request( &quot;npassword&quot; ) )
email = TRIM( Request( &quot;email&quot; ) )
street = TRIM( Request( &quot;street&quot; ) )
town = TRIM( Request( &quot;town&quot; ) )
county = TRIM( Request( &quot;county&quot; ) )
postcode = TRIM( Request( &quot;postcode&quot; ) )
cctype = Request( &quot;cctype&quot; )
ccnumber = TRIM( Request( &quot;ccnumber&quot; ) )
ccexpires = TRIM( Request( &quot;ccexpires&quot; ) )
ccname = TRIM( Request( &quot;ccname&quot; ) )

' Check For Required Fields
backpage = Request.ServerVariables( &quot;SCRIPT_NAME&quot; )
IF nusername = &quot;&quot; THEN
errorForm &quot;You must enter a username.&quot;, backpage
END IF
IF npassword = &quot;&quot; THEN
errorForm &quot;You must enter a password.&quot;, backpage
END IF
IF email = &quot;&quot; THEN
errorForm &quot;You must enter your email address.&quot;, backpage
END IF
IF street = &quot;&quot; THEN
errorForm &quot;You must enter your street address.&quot;, backpage
END IF
IF town = &quot;&quot; THEN
errorForm &quot;You must enter your town.&quot;, backpage
END IF
IF county = &quot;&quot; THEN
errorForm &quot;You must enter your county.&quot;, backpage
END IF
IF postcode = &quot;&quot; THEN
errorForm &quot;You must enter your postcode.&quot;, backpage
END IF
IF ccnumber = &quot;&quot; THEN
errorForm &quot;You must enter your credit card number.&quot;, backpage
END IF
IF ccexpires = &quot;&quot; THEN
errorForm &quot;You must enter your credit card expiration date.&quot;, backpage
END IF
IF ccname = &quot;&quot; THEN
errorForm &quot;You must enter the name that appears on your credit card.&quot;, backpage
END IF

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

' Check whether username already registered
IF alreadyUser( nusername ) THEN
errorForm &quot;Please choose a different username.&quot;, backpage
END IF

' Add New User to Database
sqlString = &quot;INSERT INTO Users ( &quot; &_
&quot;user_username, &quot; &_
&quot;user_password, &quot; &_
&quot;user_email, &quot; &_
&quot;user_street, &quot; &_
&quot;user_town, &quot; &_
&quot;user_county, &quot; &_
&quot;user_postcode, &quot; &_
&quot;user_cctype, &quot; &_
&quot;user_ccnumber, &quot; &_
&quot;user_ccexpires, &quot; &_
&quot;user_ccname &quot; &_
&quot;) VALUES ( &quot; &_
&quot; '&quot; & fixQuotes( nusername ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( npassword ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( email ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( street ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( town ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( county ) & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( postcode ) & &quot;', &quot; &_
&quot; '&quot; & cctype & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( ccnumber ) & &quot;', &quot; &_
&quot; '&quot; & ccexpires & &quot;', &quot; &_
&quot; '&quot; & fixQuotes( ccname ) & &quot;')&quot;

Con.Execute sqlString

' Use the new username and password
username = nusername
password = npassword

' Add Cookies
addCookie &quot;username&quot;, username
addCookie &quot;password&quot;, password
END SUB



SUB updateUser
' Get Registration Fields
street = TRIM( Request( &quot;street&quot; ) )
town = TRIM( Request( &quot;town&quot; ) )
county = TRIM( Request( &quot;county&quot; ) )
postcode = TRIM( Request( &quot;postcode&quot; ) )
cctype = Request( &quot;cctype&quot; )
ccnumber = TRIM( Request( &quot;ccnumber&quot; ) )
ccexpires = TRIM( Request( &quot;ccexpires&quot; ) )
ccname = TRIM( Request( &quot;ccname&quot; ) )

' Check For Required Fields
backpage = &quot;checkout.asp&quot;
IF street = &quot;&quot; THEN
errorForm &quot;You must enter your street address.&quot;, backpage
END IF
IF town = &quot;&quot; THEN
errorForm &quot;You must enter your town.&quot;, backpage
END IF
IF county = &quot;&quot; THEN
errorForm &quot;You must enter your county.&quot;, backpage
END IF
IF postcode = &quot;&quot; THEN
errorForm &quot;You must enter your postcode code.&quot;, backpage
END IF
IF ccnumber = &quot;&quot; THEN
errorForm &quot;You must enter your credit card number.&quot;, backpage
END IF
IF ccexpires = &quot;&quot; THEN
errorForm &quot;You must enter your credit card expiration date.&quot;, backpage
END IF
IF ccname = &quot;&quot; THEN
errorForm &quot;You must enter the name that appears on your credit card.&quot;, backpage
END IF

' Check for Necessary Field Values
IF INSTR( ccnumber, &quot;*&quot; ) = 0 THEN
IF NOT validCCNumber( ccnumber ) THEN
errorForm &quot;You did not enter a valid credit card number&quot;, backpage
ELSE
ccnumber = &quot;'&quot; & ccnumber & &quot;'&quot;
END IF
ELSE
ccnumber = &quot;user_ccnumber&quot;
END IF
IF NOT isDATE( ccexpires ) THEN
errorForm &quot;You did not enter a valid credit card expiration date&quot;, backpage
END IF

' Update user information in the database
sqlString = &quot;UPDATE Users SET &quot; &_
&quot;user_street='&quot; & fixQuotes( street ) & &quot;', &quot; &_
&quot;user_town='&quot; & fixQuotes( town ) & &quot;',&quot; &_
&quot;user_county='&quot; & fixQuotes( county ) & &quot;',&quot; &_
&quot;user_postcode='&quot; & fixQuotes( postcode ) & &quot;',&quot; &_
&quot;user_ccnumber='&quot; & ccnumber & &quot;', &quot; &_
&quot;user_cctype=&quot; & cctype & &quot;, &quot; &_
&quot;user_ccexpires='&quot; & ccexpires & &quot;',&quot; &_
&quot;user_ccname='&quot; & fixQuotes( ccname ) & &quot;' &quot; &_
&quot;WHERE user_id=&quot; & userID

Con.Execute sqlString
END SUB

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

I hope I have provided enough info for some help. Thanks in advance!!

Joe
 
Side note for you to keep in mind when someone helps you fix this code..

make the code send you an email with the corrections instead of allowing the users to completely modify on their own, reason being is businesses that make financial transactiosn are required to keep records for upwards of seven years, a user comes in and changes all data fields to &quot;.&quot; ( closest thing to blank ) and hence messes up your records

clientel of , uhm, not so high standards, will use methods like this to get away on payment etc, due to no 'true' records

just a FYI note.
hope the info helps and best of luck in gettting things sorted out.
 
Thanks for the reply. I'll keep that in mind, but in the meantime, I would appreciate if someone could help me out with my problem. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top