Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-09-12
4
Medium Priority
?
200 Views
Last Modified: 2011-09-20
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
%>
0
Comment
Question by:Barry62
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
jitganguly earned 400 total points
ID: 6477118
Try CStr function if it is character type or cint for numeric

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

if cstr(secid1) = cstr(secid) then
' OR if cint(secid1) = cint(secid) then
  response.write "It matched!"
end if
%
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6477123
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
%
0
 
LVL 8

Author Comment

by:Barry62
ID: 6477134
That was so easy!  Why didn't I think of that??

Thanks!
0
 
LVL 10

Expert Comment

by:Nitin Sontakke
ID: 6477136
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.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question