Forums

This topic is locked

if then

Posted 15 Aug 2002 16:38:19
1
has voted
15 Aug 2002 16:38:19 Barry Williams posted:
hey can some one tell me whats wrong with this

active = rsDetails.Fields.Item("active".Value
IF active = "false" THEN Response.Redirect("banned.asp"

i'm referring to a table in a database to find if the user name is valid or not but i keep getting errors
any help would be great
thanx

Replies

Replied 15 Aug 2002 16:46:14
15 Aug 2002 16:46:14 Vince Baker replied:
If that is copied from your page then you have some characters missing:

<%
active = (rsDetails.Fields.Item("active".Value)
IF active = "false" THEN Response.Redirect("banned.asp"
End If %>

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
hey can some one tell me whats wrong with this

active = rsDetails.Fields.Item("active".Value
IF active = "false" THEN Response.Redirect("banned.asp"

i'm referring to a table in a database to find if the user name is valid or not but i keep getting errors
any help would be great
thanx

<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Replied 15 Aug 2002 17:12:04
15 Aug 2002 17:12:04 Barry Williams replied:
no it isn't just copied. i just wrote the part that i need

&lt;% active = (rsDetails.Fields.Item("active".Value)
IF active = "false" THEN Response.Redirect("banned.asp"
End If %&gt;
is what it looks like in code view
Replied 15 Aug 2002 21:51:54
15 Aug 2002 21:51:54 Travis Brown replied:
What errors are you getting, or is it just not redirecting?

Is "active" a text or binary datatype? The values from a binary field differ from db to db.

Replied 16 Aug 2002 05:55:57
16 Aug 2002 05:55:57 Barry Williams replied:
I changed the field in the table to active_shad and this is the new statement

&lt;% activeban = (rsDetails.Fields.Item("active_shad".Value)
IF activeban = "false" THEN Response.Redirect("banned.asp"
End If %&gt;

Microsoft VBScript compilation (0x800A0400)
Expected statement

it doesn't even get to the redirecting part. it says theres an error in the IF THEN statement
Replied 16 Aug 2002 07:06:03
16 Aug 2002 07:06:03 Travis Brown replied:
Time to start tracing the problem back then. Use response.write to see what value the rs is returning. If it is a binary field it may be that it is returning yes/no or 1/0 instead of true/false. You never said whay type of field it is. Also, try taking the double quotes off the "false" value. It may be a datatype conflict (though that shouldn't make the condition err out).

&lt;% activeban = (rsDetails.Fields.Item("active_shad".Value)

response.write rsDetails.Fields.Item("active_shad"
response.end

IF activeban = "false" THEN Response.Redirect("banned.asp"
End If %&gt;

Microsoft VBScript compilation (0x800A0400)
Expected statement

it doesn't even get to the redirecting part. it says theres an error in the IF THEN statement


Replied 16 Aug 2002 17:10:30
16 Aug 2002 17:10:30 David Behan replied:
Restructure you code:

&lt;%
DIM activeban
activeban = (rsDetails.Fields.Item("active_shad".Value)
IF activeban = "false" THEN
Response.Redirect("banned.asp"
End If
%&gt;

Regards,

Dave

_________________________
WinXP : IIS 5.1 : StudioMX : ASP : VBScript
www.clicksdesign.com
Replied 17 Aug 2002 14:03:07
17 Aug 2002 14:03:07 Barry Williams replied:
ITS STILL NOT WORKING!!!!
ive tried everything.. beano ur code still won't make it work.
it will work it i don't use data from a recordset e.g


&lt;%
active = Request.ServerVariables("REMOTE_ADDR"
IF active = "127.0.0.1" THEN Response.Redirect("banned.asp"
End If %&gt;

that code works but as soon as i try using the recordset then i get the error.
if its anyhelp i'm using the variable Session("MM_Username"

i would really like to get this to work and its starting to frustrate me :


Edited by - fredman1 on 17 Aug 2002 14:09:11
Replied 17 Aug 2002 18:44:10
17 Aug 2002 18:44:10 aegis kleais replied:
Fredman, look at your entire code, and denote the following:

if you have:

if (variable = value) then action
action
end if

you'll get a problem. See, you can use if without a then ONLY if there is 1 action.
If you use multiple actions for an if, place each action on a seperate line and then add an END IF

[WRONG]

if (variable = value) then action1
action2
end if

[RIGHT]

if (variable = value) then
action1
action2
end if

Also, you're using TRUE and FALSE as text strings. Make sure that they are indeed text strings in the DB, otherwise, remove the quotes.

You may also want to do something like :

varTest = rs.Fields.Item("active".Value
Response.Write(varTest)

just to make sure that have valid data in the DB (no point in testing data in the db if the data itself is bad)

Edited by - aegiskleais on 17 Aug 2002 18:48:26

Reply to this topic