Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2013, 03:52 AM   PM User | #1
jason_kelly
Regular Coder

 
Join Date: Sep 2011
Posts: 140
Thanks: 88
Thanked 0 Times in 0 Posts
jason_kelly is an unknown quantity at this point
Creating a Table at the click of a button with classic asp

Hello,

I need your help.

I am trying to validate information, without switching the page (in this case a username, if the username is found, great, populate a textbox and dynamically create a table with the username it it). However, I am getting an error on line 75 that reads:

Code:
ADODB.Recordset

 error '800a0e78' 

Operation is not allowed when the object is closed. 

/login.asp, line 75
I haven't closed the recordset anywhere. By my knowledge it should work. What am I doing wrong?

Code:
<%
Dim cn,rs
    Set cn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.recordset")

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"

    cn.Open Server.MapPath("login.mdb")

'Default message for the user on the login page
msg = "Please login"

'Logout code. This code empties the session variable which holds the user's userID.
If Request.QueryString("action") = "logout" Then
    Session("user_id") = ""
    msg = "You have been logged out"
End If


'Check if the form has been submitted

If Request.Form("Submit") = "Test" Then

    user_name = Request.Form("user_name")
    user_pass = Request.Form("user_pass")

    mySQL = "SELECT user_id, user_name, user_pass FROM users WHERE user_name = '" & user_name & "' AND user_pass = '" & user_pass & "'"

    'Select the data from the database using the submitted data.
    rs.Open mySQL, cn

        'Check if a match was found.
        If NOT rs.EOF Then

            'Session("user_id") = rsLogin("user_id")
            'Response.Redirect("profile.asp")

            u = rs("user_name")

        Else
            'If a match was not found then output an error.
            Response.Redirect("login.asp?errmsg=Login failed")
        End If
End If
%>



<!DOCTYPE html>
<html>
<head>
</head>

<body>
<form name="form1" id="form1" method="post" action="">
  <table width="300" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td>Username</td>
      <td><input name="user_name" type="text" id="user_name" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="user_pass" type="password" id="user_pass" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Test" /></td>
    </tr>
  </table>
</form>
<input id="fileno" value="<%=u%>" type="text">


<%
        While NOT rs.EOF
%>
    <table width="200" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <th scope="col"><div align="left">username</div></th>
  </tr>

  <tr>
    <td><%=u%></td>
  </tr>
<%
        rs.MoveNext
        Wend
%>
</table>
</body>
</html>
jason_kelly is offline   Reply With Quote
Old 02-23-2013, 11:31 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Please, next time TELL US WHAT LINE the error is on, so we don't have to count lines.

Okay, so the error is here:
Code:
        While NOT rs.EOF
Did you bother to debug? Did you bother to see if, indeed, the record set *IS* open?

You really don't think that the ASP engine is making a mistake, do you?

Anyway, look carefully at your code: The only time you OPEN the recordset is after this code:
Code:
If Request.Form("Submit") = "Test" Then
And then only if the condition is true.

*CLEARLY* the first time you reach this page, that will *NOT* be true, so clearly until the <form> is submitted, the recordset WILL NOT BE OPEN.

I'm trying really hard to see what the point of your code is, but I can't. You do a WHILE loop on the recordset, but NO PLACE AT ALL inside the loop do you even TRY to get any values from the recordset. So the whole loop seems utterly pointless.

I really have no idea what you are trying to do here, so I have no idea how to help you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:35 AM.


Advertisement
Log in to turn off these ads.