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!

DB is not updating 1

Status
Not open for further replies.

chmilz

Programmer
Jan 10, 2001
94
CA
Hello all,

I am trying to add a function in my website to allow users to change their passwords after they have logged in.

I have tested my code and I get to the success page but my table doesn't get updated with the new password. here is the code from my update_password ASP page:

<!-- #include file=&quot;adovbs.inc&quot; -->
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Update Password</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<%
'Setup the strings for the old and new passwords and the Username
strOldPass = Request.Form(&quot;OldPassword&quot;)
strNewPass = Request.Form(&quot;NewPassword&quot;)
strUser = Session(&quot;User&quot;)
SQL = &quot;UPDATE Users SET UserPassword ='&quot; & strNewPass & &quot;' WHERE Username ='&quot; & strUser & &quot;'&quot;
SQL2 = &quot;SELECT UserPassword FROM Users WHERE Username = '&quot; & strUser & &quot;'&quot;

set adoConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
'set adoRS = Server.CreateObject (&quot;ADODB.RecordSet&quot;)
adoConn.Open &quot;DSN=LocalServer; UID=Standard;PWD=password&quot;
adoConn.Execute(SQL)

'adoRS.Open SQL2,adoConn

'If Trim(strNewPass) = Trim(adoRS(&quot;UserPassword&quot;)) Then
Response.Redirect(&quot;update_success.asp&quot;)
'Else
'Response.Redirect(&quot;update_fail.htm&quot;)
'End If

'set adoRS = Nothing
set adoConn = Nothing
%>


</body>
</html>


Any help is greatly appreciated!

Cheers,
Curtis
 
The code to update the DB is all commented out. Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Actually, if you look closer you can see that the update statement is exexuted in the line &quot;adoConn.Execute(SQL)&quot;.

All of the commented out stuff is just extra error checking stuff that I will implement later....

As you can see... the update statement is there and is executed but nothing happens....

Any help is greatly appreciated!

Cheers,
Chmilz
 
You may be right.... I am not sure if it does. Is that how you pass a variable from one asp page to another??

In my validate login asp page I have a line like this:

If Trim(strPassword) = Trim(adoRS(&quot;UserPassword&quot;)) Then
'If the passwords match set a session variable to true
Session(&quot;LoggedIn&quot;)=&quot;TRUE&quot;
Session(&quot;User&quot;)= strUsername

The first one works. I just thought thats how you assigned a session value. The strUsername contains the name of the user that signed in...

Did I do that right??

Cheers,
Chmilz
 
Fester,

After writing the values to the screen I see that there is no value contained in the username field!

Is there another way that I have to pass on which user is currently signed in?? Could it be done with cookies maybe???

Thanks a lot for all your help!

Cheers,
Curtis
 
Fester,

I checked my Validate Login and it worked. I just don't understand what could be going wrong!!

I will post my code from both pages in another post for you to check out...

Cheers,
Curtis
 
Validate Login ASP Page:

<body>
<%
'Get the username and password from the homepage and set the select statement
strUsername = Request.Form(&quot;Username&quot;)
strPassword = Request.Form(&quot;Password&quot;)
SQL = &quot;SELECT * FROM Users Where UserName= '&quot; & strUsername & &quot;'&quot;

set adoConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
set adoRS = Server.CreateObject (&quot;ADODB.RecordSet&quot;)
adoConn.Open &quot;DSN=LocalServer; UID=Standard;PWD=password&quot;
adoRS.Open SQL,adoConn

If adoRS.EOF Then
'The username doesn't exist, do an error.
Response.Write &quot;Username Doesn't Exist!&quot;
Else
If Trim(strPassword) = Trim(adoRS(&quot;UserPassword&quot;)) Then
'If the passwords match set a session variable to true
Session(&quot;LoggedIn&quot;)=&quot;TRUE&quot;
Session(&quot;User&quot;)= strUsername
Response.Redirect(&quot;members_main.asp&quot;)

Else
'Passwords don't match
Response.Redirect(&quot;error.asp&quot;)
End If
End If

set adoRS = Nothing
set adoConn = Nothing
%>
</body>
</html>


Update Password ASP Page:

<body>
<%
'Setup the strings for the old and new passwords and the Username
strOldPass = Request.Form(&quot;OldPassword&quot;)
strNewPass = Request.Form(&quot;NewPassword&quot;)
strUser = Session(&quot;User&quot;)
SQL = &quot;UPDATE Users SET UserPassword ='&quot; & strNewPass & &quot;' WHERE Username ='&quot; & strUser & &quot;'&quot;
SQL2 = &quot;SELECT UserPassword FROM Users WHERE Username = '&quot; & strUser & &quot;'&quot;

set adoConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
set adoRS = Server.CreateObject (&quot;ADODB.RecordSet&quot;)
adoConn.Open &quot;DSN=LocalServer; UID=Standard;PWD=password&quot;

adoConn.Execute(SQL)
If Trim(strNewPass) = Trim(adoRS(&quot;UserPassword&quot;)) Then
Response.Redirect(&quot;update_success.asp&quot;)
Else
Response.Redirect(&quot;update_fail.htm&quot;)
End If

set adoRS = Nothing
set adoConn = Nothing
%>


</body>
 
Oops, left something out of the update password page..

after the line &quot;adoConn.Execute(SQL)&quot; I have this:

adoRS.Open SQL2, adConn

Cheers,
Curtis
 
Gary,

I'm not sure... is that a browser setting or something I set in ASP?

Cheers,
Curtis
 
Gary,

I CANNOT write the value from Session(&quot;User&quot;) to my members_main page.... that must mean that my Session(&quot;Login&quot;) is not getting read either. Any way I can go about solving this? Here is all I have for ASP code in my members main page...

<%
If Session(&quot;LoggedIN&quot;) <> &quot;TRUE&quot; Then
Response.Redirect(&quot;error.asp&quot;)
strUser = Session(&quot;User&quot;)
Response.Write(strUser)
%>

The rest is all HTML code on that page....

Thanks again for all of your help!

Cheers,
Curtis
 
Best solution use hidden fields to pass the info to the next page, using either Post or Get, theres many variables associated with cookies, people can block them completely, block session cookies etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top