Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Passing Variables in a form post
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Passing Variables in a form post

 Post Reply Post Reply
Author
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post Topic: Passing Variables in a form post
    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>")
%>

Back to Top
twooly View Drop Down
Groupie
Groupie


Joined: 24 September 2003
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote twooly Quote  Post ReplyReply Direct Link To This Post 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>")
%>

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.