This topic is locked
[SOLVED]

 Compare 2 session variables

11/10/2009 6:20:19 AM
ASPRunnerPro General questions
P
Philip author

Hello,
within my event code I try to compare 2 session variables.

This is an example of my if-statement:
if SESSION("field_A") = SESSION("field_B") then

response.write "OK"

else

response.write "failed"

endif
Unfortunately the comparison fails (means that whatever value the variables have I always end up in the ELSE).
QUESTION: is my if-statement not correct?

In examples I found the comparison is done against a value or string and not another session variable.
Regards,

Philip

J
Jane 11/10/2009

Philip,
It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

P
Philip author 11/10/2009

Jane,
thanks; unfortunately the application is very big and password protected ...
Can you tell me please if (in general) my if-statement is correct / possible?
Best regards,

Philip

J
Jane 11/10/2009

Philip,
try to check if all variables is not empty before:

if not isnull(SESSION("field_A")) and not isnull(SESSION("field_B")) and SESSION("field_A") = SESSION("field_B") then

response.write "OK"

else

response.write "failed"

end if
P
Philip author 11/10/2009



Philip,
try to check if all variables is not empty before:

if not isnull(SESSION("field_A")) and not isnull(SESSION("field_B")) and SESSION("field_A") = SESSION("field_B") then

response.write "OK"

else

response.write "failed"

end if



Jane,
I already checked that with "response.write". Both variables are populated with the same value (i.e. 19).

Maybe this leads us further:
When I try

if SESSION("field_A") = 19 then
or
if SESSION("field_B") = 19 then
it works fine. My conclusion: variables are populated and are recognized as numbers not text - right?

Any ideas?
Philip

Sergey Kornilov admin 11/10/2009

Philip,
your code is correct however it all depends on what kind of data is stored in those session variables. Probably you need to convert them to numbers or make sure they are not nulls as Jane suggested.
No reasonable recommendations can be made without seeing actual code and data.

P
Philip author 11/10/2009

Hello,
I found a solution ("field_B" is actually the Session UserID; this seems to be text not number):
SESSION("field_A") = (CDbl(SESSION("field_B")))

With that I convert field_B from text to number and it works.
Thanks

Philip