Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie CFIF question

Status
Not open for further replies.

MattJenneson

Programmer
Sep 12, 2002
8
GB
All,

New to coldfusion so forgive the stupidity.

I'm trying to authenticate a user against a SQL Database but cannot use my SQL variable in a CFIF. Code is as below.
Code:
<cfquery name="PassCheck" dataSource="cfBest">
SELECT PWDCOMPARE ('" & form.Password & "',(SELECT password FROM master.dbo.syslogins WHERE name = '" & form.Login&"'))
</cfquery>

<cfif <cfoutput>#PWDCOMPARE# </cfoutput> eq "1">
      <cflocation url="Demo_Menu.htm">
<cfelse>
      <cflocation url="Password_Incorrect.htm">
</cfif>


i have tried it without the output tags and #'s but then i get an unknown vairiable error.

am i doing something stupid?

Thanks Matt
 
sorted it.

it was something stupid.

The the SQL needed to be a SELECT AS because it's a function.
 
Glad you got the sql bit.

I'm gonna give you a little bit of help though, if you don't mind...

Code:
<cfif [red]<cfoutput>[/red][blue]#[/blue][black]PWDCOMPARE[/black][blue]#[/blue][red]</cfoutput>[/red] eq [purple]"1"[/purple]>
      <cflocation url="Demo_Menu.htm">
<cfelse>
      <cflocation url="Password_Incorrect.htm">
</cfif>

I'd imagine you figured out that you can't execute a cf tag inside another tag.. And that's great...

As for the colorized version above:

. The red cfoutputs, as you probably did, are to be removed... the blue #'s don't have to be there and should not be there. They slow the cf engine (a slight bit, you won't even notice, but if you're new), its a good habit to kick now. (And of course, I'm not trying to imply that the extra character is what slows it.)

<cfif myvar is "test"> and <cfif #myvar# is "test"> do the exact same thing.

The purple [eq "1"]... First understand that in cold fusion EQ and IS serve the same purpose (as do NEQ and IS NOT). Numbers do not need to be quoted and should not be quoted. Otherwise you can end up with string comparisons that do not work sometimes... ["1"] is a string whereas [1] is a number.

Ignore the brackets ([ and ])... I thought quoting the quotes would become quite hard to read.

1 is not "1.0" but it does equal it...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top