By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

Problem with filter database by login name.. Help me Pls..

P: 1
I wan to filter the database show out information by using the user login name. Means that when that user login by entering their names n password, if correct then it will go to the other page by showing that user result only, not other user result. Can somebody help me pls?.

Following is the login page code:
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
  2. <!--#include file="Connections/conResult.asp" -->
  3. <%
  4. Dim Recordset1__MMColParam
  5. Recordset1__MMColParam = "1"
  6. If (Session("username") <> "") Then 
  7.   Recordset1__MMColParam = Session("username")
  8. End If
  9. %>
  10. <%
  11. Dim Recordset1
  12. Dim Recordset1_numRows
  13.  
  14. Set Recordset1 = Server.CreateObject("ADODB.Recordset")
  15. Recordset1.ActiveConnection = MM_conResult_STRING
  16. Recordset1.Source = "SELECT * FROM Student WHERE Name = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"
  17. Recordset1.CursorType = 0
  18. Recordset1.CursorLocation = 2
  19. Recordset1.LockType = 1
  20. Recordset1.Open()
  21.  
  22. Recordset1_numRows = 0
  23. %>
  24. <%
  25. ' *** Validate request to log in to this site.
  26. MM_LoginAction = Request.ServerVariables("URL")
  27. If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
  28. MM_valUsername=CStr(Request.Form("textfield"))
  29. If MM_valUsername <> "" Then
  30.   MM_fldUserAuthorization=""
  31.   MM_redirectLoginSuccess="Result.asp"
  32.   MM_redirectLoginFailed="Login4.asp"
  33.   MM_flag="ADODB.Recordset"
  34.   set MM_rsUser = Server.CreateObject(MM_flag)
  35.   MM_rsUser.ActiveConnection = MM_conResult_STRING
  36.   MM_rsUser.Source = "SELECT Name, ID"
  37.   If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  38.   MM_rsUser.Source = MM_rsUser.Source & " FROM Student WHERE Name='" & Replace(MM_valUsername,"'","''") &"' AND ID='" & Replace(Request.Form("textfield2"),"'","''") & "'"
  39.   MM_rsUser.CursorType = 0
  40.   MM_rsUser.CursorLocation = 2
  41.   MM_rsUser.LockType = 3
  42.   MM_rsUser.Open
  43.   If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
  44.     ' username and password match - this is a valid user
  45.     Session("MM_Username") = MM_valUsername
  46.     If (MM_fldUserAuthorization <> "") Then
  47.       Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
  48.     Else
  49.       Session("MM_UserAuthorization") = ""
  50.     End If
  51.     if CStr(Request.QueryString("accessdenied")) <> "" And false Then
  52.       MM_redirectLoginSuccess = Request.QueryString("accessdenied")
  53.     End If
  54.     MM_rsUser.Close
  55.     Response.Redirect(MM_redirectLoginSuccess)
  56.   End If
  57.   MM_rsUser.Close
  58.   Response.Redirect(MM_redirectLoginFailed)
  59. End If
  60. %>
  61. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  62. <html xmlns="http://www.w3.org/1999/xhtml">
  63. <head>
  64. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  65. <title>Untitled Document</title>
  66. </head>
  67.  
  68. <body>
  69. <table width="344" border="1" align="center">
  70.   <tr>
  71.     <td width="334" height="220"><div align="center">
  72.       <form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
  73.         <p>Username:
  74.           <input type="text" name="textfield" />
  75.         </p>
  76.         <p>Password:
  77.           <input type="password" name="textfield2" />
  78. </p>
  79.         <p>
  80.           <input type="submit" name="Submit" value="Enter" />
  81.         </p>
  82.       </form>
  83.     </div></td>
  84.   </tr>
  85. </table>
  86. </body>
  87. </html>
  88. <%
  89. Recordset1.Close()
  90. Set Recordset1 = Nothing
  91. %>

Following is the result page code:
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
  2. <!--#include file="Connections/conResult.asp" -->
  3. <%
  4. Dim Recordset1__MMColParam
  5. Recordset1__MMColParam = "1"
  6. If (Session("username") <> "") Then 
  7.   Recordset1__MMColParam = Session("username")
  8. End If
  9. %>
  10. <%
  11. Dim Recordset1
  12. Dim Recordset1_numRows
  13.  
  14. Set Recordset1 = Server.CreateObject("ADODB.Recordset")
  15. Recordset1.ActiveConnection = MM_conResult_STRING
  16. Recordset1.Source = "SELECT *  FROM CourseCode  WHERE StudentName = '" + Replace(Recordset1__MMColParam, "'", "''") + "'"  
  17. Recordset1.CursorType = 0
  18. Recordset1.CursorLocation = 2
  19. Recordset1.LockType = 1
  20. Recordset1.Open()
  21.  
  22. Recordset1_numRows = 0
  23. %>
  24. <%
  25. Dim Repeat1__numRows
  26. Dim Repeat1__index
  27.  
  28. Repeat1__numRows = 10
  29. Repeat1__index = 0
  30. Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
  31. %>
  32.  
  33. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  34. <html xmlns="http://www.w3.org/1999/xhtml">
  35. <head>
  36. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  37. <title>Untitled Document</title>
  38. </head>
  39.  
  40. <body>
  41. <table border="1" cellpadding="2" cellspacing="1">
  42.   <tr>
  43.     <td>StudentName</td>
  44.     <td>StudentID</td>
  45.     <td>Programme</td>
  46.     <td>CourseCode</td>
  47.     <td>Grade</td>
  48.     <td>Semester</td>
  49.   </tr>
  50.   <% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
  51.     <tr>
  52.       <td><%=(Recordset1.Fields.Item("StudentName").Value)%></td>
  53.       <td><%=(Recordset1.Fields.Item("StudentID").Value)%></td>
  54.       <td><%=(Recordset1.Fields.Item("Programme").Value)%></td>
  55.       <td><%=(Recordset1.Fields.Item("CourseCode").Value)%></td>
  56.       <td><%=(Recordset1.Fields.Item("Grade").Value)%></td>
  57.       <td><%=(Recordset1.Fields.Item("Semester").Value)%></td>
  58.     </tr>
  59.     <% 
  60.   Repeat1__index=Repeat1__index+1
  61.   Repeat1__numRows=Repeat1__numRows-1
  62.   Recordset1.MoveNext()
  63. Wend
  64. %>
  65. </table>
  66. </body>
  67. </html>
  68. <%
  69. Recordset1.Close()
  70. Set Recordset1 = Nothing
  71. %>
Mar 10 '08 #1
Share this Question
Share on Google+
1 Reply


jhardman
Expert 2.5K+
P: 3,405
nth,

Welcome to theScripts.com, we're glad you found it. Just a couple things you should know:

1- please enclose your code in code tags (if you hit "reply" on your original post you will see the codes I used, or you can use the provided # button). this makes it much easier to read.

2- There is no size limit, so no reason to use SMS speak. Please write out your words ("and" not "n" etc)

That said, please clarify your problem. What part is giving you trouble?

Jared
Mar 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.