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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Amending Details

Status
Not open for further replies.

kaycee79

Technical User
Jan 10, 2004
82
GB
I have a page where users can amend their personal details, once they have successfully entered their username and password. I want to change this in the sense; when a user enters their username and password, their details appear from the database, and they can change what ever details they want. I want their details to appear in text boxes. Is this possible? If so, how?

Thanks in Advance

This is the code that I am currently using;

Input Form

Code:
<HTML>
<HEAD>
<TITLE>Amend Details</TITLE>
</HEAD>

<BODY>
<div id=&quot;content&quot;>

<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;ENLARGE TEXT&quot;>



<H1><U><B>Amend Details</U></B></H1>
<BR>
<BR>
Have you changed address? If so, you can amend your details here<br>
and give us your new details. <BR>
<BR>
You must enter your username and password in order to change your details.<BR>

<form action=&quot;changedetails.asp&quot; method=&quot;post&quot;>

Username <input type=&quot;text&quot; name=&quot;txtUsername&quot; size=&quot;20&quot;><br>
Password <input type=&quot;password&quot; name=&quot;txtPassword&quot; size=&quot;20&quot;><br>
<BR>
Title <input type=&quot;text&quot; name=&quot;txtNewTitle&quot; size=&quot;20&quot;><br>
First Name <input type=&quot;text&quot; name=&quot;txtNewFirstName&quot; size=&quot;20&quot;><br>
Surname <input type=&quot;text&quot; name=&quot;txtNewSurname&quot; size=&quot;20&quot;><br>
Address 1 <input type=&quot;text&quot; name=&quot;txtNewAddress1&quot; size=&quot;20&quot;><br>
Address 2 <input type=&quot;text&quot; name=&quot;txtNewAddress2&quot; size=&quot;20&quot;><br>
Town <input type=&quot;text&quot; name=&quot;txtNewTitle&quot; size=&quot;20&quot;><br>
County <input type=&quot;text&quot; name=&quot;txtNewCounty&quot; size=&quot;20&quot;><br>
Post Code <input type=&quot;text&quot; name=&quot;txtNewPostCode&quot; size=&quot;20&quot;><br>
Email Address <input type=&quot;text&quot; name=&quot;txtNewEmailAddress&quot; size=&quot;20&quot;><br>
Telephone Number <input type=&quot;text&quot; name=&quot;txtNewTelephoneNo&quot; size=&quot;20&quot;><br>
<BR>
<input type=&quot;Submit&quot; value=&quot;Submit my New Details&quot;><BR>
<input type=&quot;Reset&quot; value=&quot;Clear&quot;>

</div>
</BODY>
</html>


ASP Code to add to DB

Code:
<!-- #include file=&quot;ProjectConnection.asp&quot; -->

<!-- METADATA TYPE=&quot;typelib&quot;
              FILE=&quot;c:\Program Files\Common Files\System\ado\msado15.dll&quot; -->

<%
	Dim strConnect
%>


<html>
<head>
<body>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;ENLARGE TEXT&quot;>


<title>Unable to Change Your Details</title>
<H1><B><U>SORRY</U></B></H1>
There has been an error with your input;
<BR>
<BR>


<%
    	Dim objRS
    	
	Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
    	sql=&quot;select * from RegisteredUsers where Username='&quot;&Request(&quot;txtUsername&quot;)&&quot;'&quot;
	objRS.Open sql, strConnect, 3,3
	
	if objRS.RecordCount <=0 then
	Response.Write &quot;The username that you have entered is invalid.&quot;
	Response.Write &quot; Please click on back on your browser and re-enter your username&quot;
	Response.End
	End If
	
	if objRS(&quot;Password&quot;)<>Request(&quot;txtPassword&quot;) then
	Response.Write &quot;The password that you have entered is invalid.&quot;
	Response.Write &quot; Please click on back on your browser and re-enter your username&quot;
	Response.End
	End if
	
    	objRS.Fields(&quot;Title&quot;) = Request.Form(&quot;txtNewTitle&quot;)
	objRS.Fields(&quot;First Name&quot;) = Request.Form(&quot;txtNewFirstName&quot;)
	objRS.Fields(&quot;Address 1&quot;) = Request.Form(&quot;txtNewAddress1&quot;)
	objRS.Fields(&quot;Address 2&quot;) = Request.Form(&quot;txtNewAddress2&quot;)
	objRS.Fields(&quot;Town&quot;) = Request.Form(&quot;txtNewTown&quot;)
	objRS.Fields(&quot;County&quot;) = Request.Form(&quot;txtNewCounty&quot;)
	objRS.Fields(&quot;Post Code&quot;) = Request.Form(&quot;txtNewPostCode&quot;)
	objRS.Fields(&quot;Telephone Number&quot;) = Request.Form(&quot;txtNewTelephoneNo&quot;)
	objRS.Fields(&quot;Email Address&quot;) = Request.Form(&quot;txtNewEmailAddress&quot;)
	
	objRS.Update
    	
	objRS.Close
    	Set objRS = Nothing
    	
	Response.Redirect &quot;changedetailsconfirmation.asp&quot;

%> 


Or click <a href=&quot;amenddetails.asp&quot;>here</a>
</div>
</body>
</html>


 
All you really need to do is reverse the procedure you have above. So something like this will read your inputs back out into the ammend form. Basically read them out into a recordset, assign them to some variables then set the Value property of your textboxes in your form.

Eg
<%
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
sql=&quot;select * from RegisteredUsers where Username='&quot;&Request(&quot;txtUsername&quot;)&&quot;'&quot;
objRS.Open sql, strConnect, 3,3

If Not objRS.EOF Then

strTitle = objRS.Fields(&quot;Title&quot;)
strFirstName = objRS.Fields(&quot;First Name&quot;)
'... etc for each field you want to read out
Else
'Record doesn't exist
Response.Write (&quot;No record found!&quot;)
End If

%>
then your html form might look something like this:

Title <input type=&quot;text&quot; name=&quot;txtNewTitle&quot; size=&quot;20&quot; value=&quot;<%=strTitle%>&quot;><br>
First Name <input type=&quot;text&quot; name=&quot;txtNewFirstName&quot; size=&quot;20&quot; value=&quot;<%=strFirstName%>&quot;>


Just a snippet of the sort of thing you might want to try!
 
I tried this out, and this is what I did, but I can not get to it work, can you help me please;

I do not think I am on the right track.

Input Form (user enters their username and password)

<html>
<head>
<title>Change Details</title>
</head>
<BR>
Please enter your details<BR>
<BR>

<form action=&quot;changedetails.asp&quot; method=&quot;post&quot;>
Username <input type=&quot;text&quot; name=&quot;txtUsername&quot;><BR>
Password <input type=&quot;password&quot; name=&quot;txtPassword&quot;><BR>
<BR>

<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submits&quot;><BR>
<input type=&quot;Reset&quot; name=&quot;Reset&quot; value=&quot;Clear&quot;>

<BR>
</body>
</html>

Check Code (checks the database to see if the user is valid, and if so, bring their details out)

<!-- #include file=&quot;clock.inc&quot; -->

<!-- #include file=&quot;ProjectConnection.asp&quot; -->

<!-- METADATA TYPE=&quot;typelib&quot;
FILE=&quot;c:\Program Files\Common Files\System\ado\msado15.dll&quot; -->




<html>
<head>
<body>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<body onload=&quot;StartClock()&quot; onunload=&quot;KillClock()&quot;>
<form name=&quot;theClock&quot;>
<input type=text name=&quot;theTime&quot; size=6><% Response.Write Date %><BR>

<title>Unable to Change Your Details</title>
<H1><B><U>SORRY</U></B></H1>
There has been an error with your input;
<BR>
<BR>


<%
Dim objRS, strConnect

Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
sql=&quot;select * from RegisteredUsers where Username='&quot;&Request(&quot;txtUsername&quot;)&&quot;'&quot;
objRS.Open sql, strConnect, 3,3

if objRS.RecordCount <=0 then
Response.Write &quot;The username that you have entered is invalid.&quot;
Response.Write &quot; Please click on back on your browser and re-enter your username&quot;
Response.End
End If

if objRS(&quot;Password&quot;)<>Request(&quot;txtPassword&quot;) then
Response.Write &quot;The password that you have entered is invalid.&quot;
Response.Write &quot; Please click on back on your browser and re-enter your username&quot;
Response.End
End if

strTitle = objRS.Fields(&quot;Title&quot;)
strFirstName = objRS.Fields(&quot;First Name&quot;)
strSurname = objRS.Fields(&quot;Surname&quot;)
strAddress1 = objRS.Fields(&quot;Address 1&quot;)
strAddress2 = objRS.Fields(&quot;Address 2&quot;)
strTown = objRS.Fields(&quot;Town&quot;)
strCounty = objRS.Fields(&quot;County&quot;)
strPostCode = objRS.Fields(&quot;Post Code&quot;)
strEmailAddress = objRS.Fields(&quot;EmailAddress&quot;)
strTelephoneNo = objRS.Fields(&quot;Telephone Number&quot;)



objRS.Close
Set objRS = Nothing

Response.Redirect &quot;changedetailsconfirmation.asp&quot;

%>


Or click <a href=&quot;amenddetails.asp&quot;>here</a>
</div>
</body>
</html>


Display Code (display the details of the user from the database)

<!--#include file = &quot;clock.inc&quot; -->

<HTML>
<HEAD>
<TITLE>Amend Details</TITLE>
</HEAD>

<BODY>
<div id=&quot;content&quot;>

<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<body onload=&quot;StartClock()&quot; onunload=&quot;KillClock()&quot;>
<form name=&quot;theClock&quot; action=&quot;changedetails.asp&quot; METHOD=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;theTime&quot; size=6><% Response.Write Date %>


<H1><U><B>Amend Details</U></B></H1>
<BR>
<BR>
Have you changed address? If so, you can amend your details here<br>
and give us your new details. <BR>
<BR>
You must enter your username and password in order to change your details.<BR>



Username <input type=&quot;text&quot; name=&quot;txtUsername&quot; size=&quot;20&quot;><br>
Password <input type=&quot;password&quot; name=&quot;txtPassword&quot; size=&quot;20&quot;><br>
<BR>
Title <input type=&quot;text&quot; name=&quot;txtNewTitle&quot; size=&quot;20&quot; value=&quot;<%=strTitle%>&quot;><br>
First Name <input type=&quot;text&quot; name=&quot;txtNewFirstName&quot; size=&quot;20&quot; value=&quot;<%=strFirstName%>&quot;><br>
Surname <input type=&quot;text&quot; name=&quot;txtNewSurname&quot; size=&quot;20&quot; value=&quot;<%=strSurname%>&quot;><br>
Address 1 <input type=&quot;text&quot; name=&quot;txtNewAddress1&quot; size=&quot;20&quot; value=&quot;<%=strAddress1%>&quot;><br>
Address 2 <input type=&quot;text&quot; name=&quot;txtNewAddress2&quot; size=&quot;20&quot; value=&quot;<%=strAddress2%>&quot;><br>
Town <input type=&quot;text&quot; name=&quot;txtNewTitle&quot; size=&quot;20&quot; value=&quot;<%=strTown%>&quot;><br>
County <input type=&quot;text&quot; name=&quot;txtNewCounty&quot; size=&quot;20&quot; value=&quot;<%=strCounty%>&quot;><br>
Post Code <input type=&quot;text&quot; name=&quot;txtNewPostCode&quot; size=&quot;20&quot; value=&quot;<%=strPostCode%>&quot;><br>
Email Address <input type=&quot;text&quot; name=&quot;txtNewEmailAddress&quot; size=&quot;20&quot; value=&quot;<%=strEmailAddress%>&quot;><br>
Telephone Number <input type=&quot;text&quot; name=&quot;txtNewTelephoneNo&quot; size=&quot;20&quot; value=&quot;<%=strTelephoneNo%>&quot;><br>
<BR>
<input type=&quot;Submit&quot; name=&quot;Submit&quot; value=&quot;Submit my New Details&quot;><BR>
<input type=&quot;Reset&quot; name=&quot;Reset&quot; value=&quot;Clear&quot;>

</div>
</BODY>
</html>

 
How I've always done updates is as follows...

Displaying the details and updating the database take place on the same page.
Code:
'File's Name is DetailsEdit.asp
varEdit = Request.Form(&quot;Edit&quot;)
If varEdit = &quot;&quot; or IsNull(varEdit) Then
	varEdit = &quot;ShowDetails&quot;
Else
	varEdit = &quot;Edit&quot;
End If

Select Case varEdit
	Case &quot;ShowDetails&quot;
		'Connect to the database
		'Create a Recordset to grab all of the values you want to display to the user to change
		strFirstName = objRS.Fields(&quot;First Name&quot;)
		strSurname = objRS.Fields(&quot;Surname&quot;)
		strAddress1 = objRS.Fields(&quot;Address 1&quot;)
		'And so on and so forth
		'You would then use this information in the Value of the form inputs to display it
		objRS.Close
		Set objRS = Nothing
	Case &quot;Edit&quot;
		'Again connect to the database
		'Create a Recordset
		objRS.Open sql, Conn, 1, 2
		objRS(&quot;First Name&quot;) = Request.Form(&quot;txtFirstName&quot;)
		objRS(&quot;Surname&quot;) = Request.Form(&quot;txtSurname&quot;)
		objRS(&quot;Address 1&quot;) = Request.Form(&quot;txtAddress1&quot;)
		'And so on and so forth
		
		objRS.Update
		objRS.Close
		Set objRS = Nothing
		Response.Redirect(&quot;wherever you want them to go.asp&quot;)
End Select
%>
<form action=&quot;DetailsEdit.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; value=&quot;Edit&quot; name=&quot;Edit&quot;>
<input type=&quot;text&quot; name=&quot;txtFirstName&quot; value=&quot;<%= strFirstName %><br />
<input type=&quot;text&quot; name=&quot;txtSurname&quot; value=&quot;<%= strSurname %><br />
<input type=&quot;text&quot; name=&quot;txtAddress1&quot; value=&quot;<%= strAddress1 %><br />
<!-- And so on and so forth.  Notice the hidden form element &quot;Edit&quot;  This will post back to this page and cause the Select Case to use the Update code instead of the Display code -->
<input type=&quot;submit&quot; value=&quot;Update&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top