Closed Thread Icon

Topic awaiting preservation: Redirect problem (ASP) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12955" title="Pages that link to Topic awaiting preservation: Redirect problem (ASP) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Redirect problem (ASP) <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 10-28-2003 03:19

Hi, guys. This is what I did:

code:
Dim username,password
username = Request.Form("username")
password = Request.Form("password")
If username = "" OR password = "" Then
Response.Redirect("index.asp")
Else
Dim cn,sql
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("database.mdb") &";Persist Security Info=False"
Set sql = cn.Execute("SELECT * FROM login WHERE field1 LIKE '" & username & "' AND field2 LIKE '" & password & "'")
If sql.EOF Then

Response.Write("Hey, you wrong!")
Response.Redirect("index.asp")

Else
Session("username") = username
Response.Write("Thank you, " & username & " welcome!")
End if
End if
%>



Basically this is login system. If user enter existing username and passowrd, write thanks for your login.
But if user enter wrong name or password, write "Hey, you wrong". The problem is I never see that when I enter wrong name and password. When I see code:

code:
If sql.EOF Then

Response.Write("Hey, you wrong!")
Response.Redirect("index.asp")

Else



After writing those message, ASP redirecting to index.asp. So I can see why not but I cannot know how to solve this problem. I just wanna message on the same page or Javascript alert or whatever to remind user.

Do you have any ideas how to solve this????

Hiroki Kozai

jdauie
Bipolar (III) Inmate

From: Missoula, MT
Insane since: Jan 2003

posted posted 10-28-2003 05:25

Why do you need to redirect to "index.asp" on a failed login?

If you want to print that out, then ...

code:
If sql.EOF Then
Response.Write("Hey, you wrong!")
Else



... otherwise, redirect to an error page, like "error.asp" or "index.asp?error" where all the page contains is an error message.

[edit]
Also, in terms of your code ... make sure that you close your connection object before you leave the page.
That means that you need to make sure it is closed before any Response.Redirect's occur. Otherwise you will be cluttering up your server's memory with an unclosed connection every time you use this page. You may not notice the issue with this page, because it does not modify the database contents, but with access databases in general, if you are inserting data on a page, and you redirect without closing the connection, the page you redirect to might display the old data, rather that the data that was just inserted.
[/edit]

[This message has been edited by jdauie (edited 10-28-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu