Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check a database for records and redirect if no matches

Status
Not open for further replies.

rnowrang

IS-IT--Management
May 6, 2004
27
US
I am using dreamweaver to filter a record set (ASP)with a form parameter. If no matches are found I want to redirect the page to a page which states that there were no matches found. How do I check for no matches. You are my last resort. Can someone please help. Thanks.

Rajeev
 
Do you have some code that you are already using that is failing? Or do you need an outline?

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Here is the code. Thanks!!!!!!!

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/connNCF.asp" -->
<%
Dim rsUser__MMColParam
rsUser__MMColParam = "1"
If (Request.Form("email") <> "") Then
rsUser__MMColParam = Request.Form("email")
End If
%>

<%
Dim rsUser
Dim rsUser_numRows

Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.ActiveConnection = MM_connNCF_STRING
rsUser.Source = "SELECT name, email, password FROM users WHERE email = '" + Replace(rsUser__MMColParam, "'", "''") + "'"
rsUser.CursorType = 0
rsUser.CursorLocation = 2
rsUser.LockType = 1
rsUser.Open()

If (rsUser_numRows = "") Then
Response.Redirect("forgot_password_error.asp")
Response.End
End If

rsUser_numRows = 0
%>

<%
Dim mail
Dim emailstr, passwordstr

emailstr = Request("email")
passwordstr = rsUser("password")

set mail=server.CreateObject("CDONTS.NewMail")
mail.From= "ncf@4fellowship.com" ' like my.email.addr@comsoltech.com
mail.To = emailstr ' like john.doe@comsoltech.com
mail.Subject = "New Community Fellowship Password confirmation"
mail.Body = "Dear Sir/Madam," & vbcrlf & vbcrlf & "Here is the login information you needed:" & vbcrlf & vbcrlf & "User email: " & emailstr & vbcrlf & "User Password: " & passwordstr & vbcrlf & vbcrlf & "Please join us again at May God Bless you." & vbcrlf & vbcrlf & "Sincerely," & vbcrlf & "New Community Fellowship" & vbcrlf & vbcrlf & "------------------------------------" & vbcrlf & "New Community Fellowship" & vbcrlf & "Phone: 301-270-6777" & vbcrlf & "Email: ncf@4fellowship.com" & vbcrlf & "mail.MailFormat = 1 ' 0 = MIME, 1 = Text
mail.Importance = 1 ' 0 =High, 1 = Medium, 2 = Low
'mail.attachFile ("c:\images\mypicture.gif") ' you can also attach files
mail.Send
set mail=nothing

Response.Redirect("thank_you_forgot_pass.asp")
Response.End
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>New Community Fellowship: Forgot password</title>
</head>

<body>
</body>
</html>
<%
rsUser.Close()
Set rsUser = Nothing
%>
 
first you'll need to put <%response.buffer=true%> at the very top of the file, then where you have :

If (rsUser_numRows = "") Then
Response.Redirect("forgot_password_error.asp")
Response.End
End If

change that to :
if rsuser.EOF Then

....

that should patch you up there

also if you change all this :
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.ActiveConnection = MM_connNCF_STRING
rsUser.Source = "SELECT name, email, password FROM users WHERE email = '" + Replace(rsUser__MMColParam, "'", "''") + "'"
rsUser.CursorType = 0
rsUser.CursorLocation = 2
rsUser.LockType = 1
rsUser.Open()

to just this :
Set rsUser = ActiveConnection.Execute "SELECT name, email, password FROM users WHERE email = '" + Replace(rsUser__MMColParam, "'", "''") + "'"


it might help ease some headhaches in regards to future debugging.

[thumbsup2]DreX
aKa - Robert
 
Maybe I should just take shorter lunches when I'm trying to help... *sigh* Thanks, DreXor

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
lol chop sorry didn't mean to rip a post out from under you :) just trying to help

[thumbsup2]DreX
aKa - Robert
 
No, by all means, that's what we're here for... Goodness knows that I don't always have the time to answer as promptly as I'd sometimes like. At least you're there to help cover for me. [thumbsup]

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top