Solved

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

Posted on 2001-09-12
4
197 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 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 9

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting to multiple databases to create a Dashboard 5 97
Designing forms 3 70
MS SQL and column defined as time 7 36
StoredProcedure to JSON query faulty syntax 2 45
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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

710 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