Link to home
Start Free TrialLog in
Avatar of Barry62
Barry62Flag for United States of America

asked on

Values from request.form variables won't compare , but hard-coded ones will.

I have a piece of code which is baffling me.

I am trying to compare one variable, which has been loaded from a request.form object, with another one which has been loaded withing the ASP.  For testing, I am comparing the two and if they are equal I am writing a message to the screen.  

When I compare the two, I don't get any message, even though the values are equal when I write them out separately.  If I plug a value into the request variable and compare them, I get my message.

Why won't my comparisons work with imported data?

Here is some sample code:

The Form--
<form name=email method=post action="mailit.asp">
<input type=hidden name=secid value="match me">
</form>

The ASP--
<%
secid = request.form("secid")
secid1 = "match me"

if secid1 = secid then
   response.write "It matched!"
end if
%>
ASKER CERTIFIED SOLUTION
Avatar of jitganguly
jitganguly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jitganguly
jitganguly

Also you may want to use trim function Like

<%
secid = request.form("secid")
secid1 = "match me"

if cstr(Trim(secid1)) = cstr(Trim(secid)) then
 response.write "It matched!"
end if
%
Avatar of Barry62

ASKER

That was so easy!  Why didn't I think of that??

Thanks!
Avatar of Nitin Sontakke
For sure implementation please use both of the "jitganguly"'s suggestions. Use conversion functions to get correct values.

The trouble you are having is because all variables in all scripting languages are of data type variant and need explicit conversion before comparison.