Solved

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

Posted on 2001-09-12
4
190 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
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
jitganguly earned 100 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 6

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now