Print Page | Close Window

Passing Variables in a form post

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6735
Printed Date: 31 March 2026 at 6:23pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Passing Variables in a form post
Posted By: twooly
Subject: Passing Variables in a form post
Date Posted: 26 October 2003 at 4:19pm

Ok I am having a little problem.  Basicly I am creating a page so admins can change user's passwords based on their ID.  The outline of the page works like this (hoping).  If you aren't posting to the page the form is shown.  IF you are posting then the results are posted to the db.  The problem I am having is keeping the ID through the post so the second part of the page is posted.  I highlighted the line I think is causing me some troubles.  Thanks an advance for advice.

--Todd

 

<%
Dim mode
'Dimension Variables
Dim strUserName 'Holds the name of the user
Dim userID
Dim adoCon         'Holds the Database Connection Object
Dim rsAdmin   'Holds the recordset for the records in the database
Dim strSQL          'Holds the SQL query to query the database

userID = Request.querystring("ID")
strPassword = Request.Form("txtPassword")

If Request.querystring("mode") = "changepassword" then

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("site.mdb")

'Create an ADO recordset object
Set rsAdmin = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "UPDATE tblUsers SET tblUsers.password='" & strPassword & "' WHERE ID =" & userID


'Open the recordset with the SQL query
rsAdmin.Open strSQL, adoCon

Set rsAdmin = Nothing
Set adoCon = Nothing
Response.Redirect"main.asp"

End If

  Response.Write ("<table align='right'><tr><td><a href='main.asp'><img src='images/home2_324.gif' alt='Home' border='0'></a></td><td><a href='profile.asp?mode=view'><img src='images/search_16.gif' alt='View Profile' border='0'></a></td><td><a href='profile.asp?mode=edit'><img src='images/save_16.gif' alt='Edit Profile' border='0'></a></td><td><a href='profile.asp?mode=password'><img src='images/security.gif' alt='Change Password' border='0'></a></td><td><a href='logout.asp'><img src='images/Log-Off_324.gif' alt='Logoff' border='0'></a></td></tr></table> <br><br><br><br>")
  Response.Write ("<form name='Profile' method='post' action='changepass.asp?mode=changepassword&ID='" & userID & "'>")
  Response.Write ("<br><b>Change Password</b><br><br>")
  Response.Write ("<input type='Password' name='txtPassword'")
  Response.Write ("<br><br><br>")
  Response.Write ("<input type='image' src='images/submit3.jpg' name='Submit' value='Enter' alt='Enter'>")
  Response.Write ("</form>")
  Response.Write ("<br><br><a href=main.asp><img src='images/back_16.gif' border='0' alt='Go Back'></a>")
%>




Replies:
Posted By: twooly
Date Posted: 26 October 2003 at 5:19pm

Got it figured out.  I just did it through a hidden field.  Here is the code if intersted

<%
Dim mode
'Dimension Variables
Dim strUserName 'Holds the name of the user
Dim userID
Dim adoCon         'Holds the Database Connection Object
Dim rsAdmin   'Holds the recordset for the records in the database
Dim strSQL          'Holds the SQL query to query the database

userID = Request.querystring("ID")

 

If Request.querystring("mode") = "changepassword" then

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("site.mdb")

'Create an ADO recordset object
Set rsAdmin = Server.CreateObject("ADODB.Recordset")

strUserID = Request.Form("txtID")
strPassword = Request.Form("txtPassword")


'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "UPDATE tblUsers SET tblUsers.password='" & strPassword & "' WHERE ID =" & strUserID


'Open the recordset with the SQL query
rsAdmin.Open strSQL, adoCon

Set rsAdmin = Nothing
Set adoCon = Nothing
Response.Redirect"main.asp"

End If

  Response.Write ("<table align='right'><tr><td><a href='main.asp'><img src='images/home2_324.gif' alt='Home' border='0'></a></td><td><a href='profile.asp?mode=view'><img src='images/search_16.gif' alt='View Profile' border='0'></a></td><td><a href='profile.asp?mode=edit'><img src='images/save_16.gif' alt='Edit Profile' border='0'></a></td><td><a href='profile.asp?mode=password'><img src='images/security.gif' alt='Change Password' border='0'></a></td><td><a href='logout.asp'><img src='images/Log-Off_324.gif' alt='Logoff' border='0'></a></td></tr>")
  Response.write ("<tr><td></td><td><a href='admin.asp?mode=add'><img src='images/add_account.gif' alt='Add Account' border='0'></a></td><td><a href='admin.asp?mode=admin'><img src='images/add_admin.gif' alt='Add Admin' border='0'></a></td><td><a href='admin.asp?mode=listusers'><img src='images/editaccounts.gif' alt='Edit Accounts' border='0'></a></td><td><a href='admin.asp?mode=reports'><img src='images/reports.gif' alt='Reports' border='0'></a></td></tr></table> <br><br><br><br>")
  Response.Write ("<form name='Profile' method='post' action='changepass.asp?mode=changepassword'>")
  Response.Write ("<br><b>Change Password</b><br><br>")
  Response.Write ("<input type='Password' name='txtPassword'>")
  Response.Write ("<input type=hidden value='" & userID & "' name='txtID'><br><br><br>")
  Response.Write ("<input type='image' src='images/submit3.jpg' name='Submit' value='Enter' alt='Enter'>")
  Response.Write ("</form>")
  Response.Write ("<br><br><a href=main.asp><img src='images/back_16.gif' border='0' alt='Go Back'></a>")
%>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net