ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 4th, 2009, 01:05 PM
mike777 mike777 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 11 mike777 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 12 sec
Reputation Power: 0
VBScript - Database - Recordset - Why is passed in value not being matched with fields.item

Hi, I'm using access backend and I just want a form value to be matched up with a fields record on submit. My code is below...

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim conn, sConnString
Set conn = Server.CreateObject("ADODB.Connection")
sConnString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("database\myDB.mdb")
conn.Open(sConnString)

Set rs = Server.CreateObject("ADODB.Recordset")
'rs.Open "SELECT ID FROM tblIDs ORDER BY ID", conn
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<%
'login
If Request.ServerVariables("REQUEST_METHOD") <> "POST" Then
Response.Write("<p>Please Log in with provided ID Number:</p>")
Response.Write("<form id=""form1"" name=""form1"" action=""Index.asp"" method=""Post"">")
Response.Write("<input type=""text"" id=""IDLogin"" name=""IDLogin"" /><br />")
Response.Write("<input type=""submit"" id=""loginSubmit"" name=""loginSubmit"" value=""Login"" /><br />")
Response.Write("</form>")
End If

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
rs.open "SELECT ID FROM tblIDs WHERE ID = 1", conn
If rs.RecordCount > 0 Then
Response.Redirect("Index1.asp?ID=" & Request.Form("IDLogin"))
End If

' Do while Not rs.Eof
' if Request.Form("coachIDLogin") = rs.Fields.Item("coachID") Then
' response.Redirect("Index1.asp?ID=" & Request.Form("IDLogin"))
' End If
' rs.MoveNext
'Loop
End If
%>
</body>
</html>

the bolded part above is where it's failing. The code is not going into the block where it detects if a record match is found. It just won't find a match it seems! above, I even just hardcoded a value in. And it's not detecting it.

Reply With Quote
  #2  
Old November 4th, 2009, 03:10 PM
bigmike1212's Avatar
bigmike1212 bigmike1212 is offline
Option Explicit, baby.
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2009
Location: Neighborhood of Make-Believe
Posts: 554 bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 17 h 55 m 27 sec
Reputation Power: 146
I wouldn't check using request.servervariables. I'm sure one can do it that way, but I thougth sometimes the server stuff has values and sometimes it doesn't depending on where the user came from. A page that submits to itself complicates things also I think. Others will know better.

I would use the submit button.

If Request.Form("loginSubmit") = "Login" Then
__________________
Fremen United! Folding@Home team ID 169647. All Fremen welcome.

Reply With Quote
  #3  
Old November 4th, 2009, 03:11 PM
mike777 mike777 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 11 mike777 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 12 sec
Reputation Power: 0
Quote:
Originally Posted by bigmike1212
I wouldn't check it request.servervariables. I'm sure one can do it that way, but I thougth sometimes the server stuff has values and sometimes it doesn't depending on where the user came from. A page that submits to itself complicates things also I think. Others will know better.

I would use the submit button.

If Request.Form("loginSubmit") = "Login" Then


Hm, well that would work just to make sure they clicked login, but I want to make sure they are entering a number that will be in the db

Reply With Quote
  #4  
Old November 4th, 2009, 03:15 PM
bigmike1212's Avatar
bigmike1212 bigmike1212 is offline
Option Explicit, baby.
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2009
Location: Neighborhood of Make-Believe
Posts: 554 bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 17 h 55 m 27 sec
Reputation Power: 146
Quote:
Originally Posted by mike777
Hm, well that would work just to make sure they clicked login, but I want to make sure they are entering a number that will be in the db


Yes, you check if they hit login. If they did you do your SQL query and authenticate them. If they didn't you show them the login form. Just what you are doing now essentially just using a different method to make the choice.

Reply With Quote
  #5  
Old November 4th, 2009, 11:28 PM
bigmike1212's Avatar
bigmike1212 bigmike1212 is offline
Option Explicit, baby.
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2009
Location: Neighborhood of Make-Believe
Posts: 554 bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 17 h 55 m 27 sec
Reputation Power: 146
Mike777,

This is the unsophisticated amateur login script I use. Maybe it will help your thinking.
asp Code:
Original - asp Code
  1. <%@ Language="VBScript" %>
  2. <%Option Explicit %>
  3. <%Response.Expires = -1000 %>
  4. <%Response.Buffer = True %>
  5.  
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  7.    "http://www.w3.org/TR/html4/strict.dtd">
  8. <html>
  9.  
  10. <head>
  11. <title>login.asp</title>
  12.  
  13.  
  14. <h2>Login</h2>
  15.  
  16.  
  17. <%
  18. 'set up a function to clean user input
  19. dim regex
  20. Function DeleteChars(str)
  21. Set regex = New RegExp
  22. regex.pattern="(http://|\.js|[\\{}':;%()])"
  23. regex.Global = True
  24. DeleteChars = regex.Replace(str,"")
  25. Set regex = Nothing
  26. End Function
  27.  
  28. 'heart of the matter
  29. If Request.Form("submit") = "Login" Then
  30. CheckLoginForm
  31. Else
  32. ShowLoginForm
  33. End If
  34. %>
  35.  
  36.  
  37. <%
  38. Sub CheckLoginForm
  39.  
  40. Dim rs, data_source, SQL, buser_id, bpass
  41.  
  42. data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &_
  43. Server.MapPath("databasename.mdb")
  44. set rs = Server.CreateObject("ADODB.Recordset")
  45.  
  46. 'get your user submitted login info
  47. buser_id = request.form("username")
  48. bpass= request.form("password")
  49.  
  50. 'clean it
  51. buser_id= DeleteChars(buser_id)
  52. bpass= DeleteChars(bpass)
  53.  
  54. 'go see if it exists
  55. SQL= "SELECT * FROM table where user='" & buser_id & "' and pass='" & bpass & "'"
  56. rs.Open SQL, data_source
  57.  
  58. 'if it is eof then it doesn't exist so don't let them in
  59. If rs.Eof Then
  60. Response.Write "<p>Please log in.</p>"
  61. ShowLoginForm
  62. Else
  63. 'if it exists they are good to go let them in
  64. Session("logged_in") = True
  65. Session("user_logged_in") = rs("user")
  66. response.redirect "main.asp"
  67. End If
  68. End Sub
  69. %>
  70.  
  71.  
  72. <p>
  73. <% Sub ShowLoginForm %>
  74.  
  75. <!-- basic form -->
  76. <form name="form" style="width:30%;" action="login.asp" method="post">
  77.  
  78. <fieldset>
  79.     <legend>Login</legend>
  80.  
  81. <label for="username"> Username:</label>
  82. <input name="username" id="username" type="text" />
  83. <br>
  84. <label for="password"> Password:</label>
  85. <input name="password" id="password" type="password" />
  86.  
  87. </fieldset>
  88. <br>
  89. <input class="fm-req" id="fm-submit" name="Submit" value="Login" type="submit" />
  90. </form>
  91. <% End Sub %>
  92. </p>
  93.  
  94. </body>
  95. </html>


Then on your pages behind the login you check to see if they are logged in

asp Code:
Original - asp Code
  1. <%@ Language="VBScript" %>
  2. <% Option Explicit %>
  3. <%
  4. Response.CacheControl = "no-cache"
  5. Response.AddHeader "Pragma", "no-cache"
  6. Response.AddHeader "cache-control","private"
  7. Response.Expires = -1%>
  8.  
  9. <%
  10. If Session("logged_in") <> True Then
  11. Response.Redirect("login.asp")
  12. End If
  13. %>


You can then echo back on those pages with:
asp Code:
Original - asp Code
  1.  
  2. <div style="float:right;">
  3. <p>Logged in as: <%= Session("user_logged_in") %>
  4. </div>

HTH,

BigMike

Last edited by bigmike1212 : November 4th, 2009 at 11:32 PM.

Reply With Quote
  #6  
Old November 7th, 2009, 10:00 PM
bigmike1212's Avatar
bigmike1212 bigmike1212 is offline
Option Explicit, baby.
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2009
Location: Neighborhood of Make-Believe
Posts: 554 bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level)bigmike1212 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 17 h 55 m 27 sec
Reputation Power: 146
You're welcome.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > VBScript - Database - Recordset - Why is passed in value not being matched with fields.item


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek