View Full Version : response.redirect
crmpicco
02-08-2005, 11:21 AM
<%
rscheck=con.execute("select * from authusers_reg where agencyid = '"& agencyid &"'")
if rscheck = "" then
response.redirect "reg.asp"
end if
%>
I have this code above.
I am looking for the script to do a check on the authusers_reg to see if there are any records matching the 'agencyid' which is MK. If there are NOT then I want it to redirect the user to 'reg.asp'.
Would this code work?
Thanks.
Picco
jaywhy13
02-08-2005, 12:19 PM
You are attempting to store the result of a ms query in a variable. The result of such a query will return you what is called a recordset. The recordset has its own properties which you can find at this link here (http://www.w3schools.com/ado/ado_ref_recordset.asp).
However to quickly explain: the recordset has a pointer. There are two common positions... BOF - beggining of file and EOF - end of file. So if your recordset object say "RS" then if RS.EOF is true then the recordset is at the end of the record. So in the case that ur query return no records, RS.EOF will be true and so will RS.BOF.
So you'd do summin like this
rsObj=Conn.execute sqlStatement
if rsObj.EOF then
'This query returned no results
'redirecting to some page
else
'Query returned results
end if
Hope that was helpful!
ghell
02-08-2005, 01:46 PM
you can do the redirect in one line if the rest of the code is on the same page
Set rsCheck = objConn.Execute("SELECT....")
If rsCheck.EOF Then Response.Redirect "reg.asp"
Set rsCheck = Nothing
'..anything here will only be loaded if the page is not redirected.. an if else endif may be better it depends what you put in here
however, this looks like a login script so beware of sql injection with this method of checking a login
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.