Skip to main content
Participant
June 24, 2008
Question

CFQuery and returning values

  • June 24, 2008
  • 2 replies
  • 633 views
I need help querying a database based on the current user signed in (right now we will put the user in the code itself i.e. if username = swat4 and this value = whatever) and then return true if those conditions apply so I can use a cfif to determine what content to display.

The datasource is SiteAdmin. The Table is WWWAdminTable. And the fields include NTUsername, LASNav, WWWNav, EngNav, BusNav, Control. These fileds are mainly a 0 or 1 value, 1 meaning they have permission to view that navigation page.

Here's the code I have started, but I feel it might be going in the wrong direction. I need to know how I can use what I have to query the database, if a username there exists, and the value of (let's say WWWNav) is 1, then using a cfif statement say something like - cfif query getPermissions = true. Please help and thank you.


<cfquery name = "getPermissions" datasource = "SiteAdmin">
SELECT NTUsername, LASNav, WWWNav, EngNav, Control
FROM WWWAdminTable
WHERE

<cfquery>
    This topic has been closed for replies.

    2 replies

    swat4Author
    Participant
    June 24, 2008
    I received this error:

    Element NTUSERNAME is undefined in FORM.

    WHERE NTUsername = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.NTUsername#">
    Participating Frequently
    June 24, 2008
    Hi swat4,

    yes, you need a form to pass this value and later to compare.
    where the user will enter with the variable for comparison in the database?
    substitute the variable form for the which you are using to rescue this value.
    Example:
    <cfset variables.txtNTUsername = "username valid is here"/>

    <cfquery name="getPermissions" datasource="SiteAdmin">
    SELECT NTUsername, LASNav, WWWNav, EngNav, Control
    FROM WWWAdminTable
    WHERE NTUsername = <cfqueryparam cfsqltype="cf_sql_varchar" value="# variables.txtNTUsername#">
    <cfquery>
    swat4Author
    Participant
    June 24, 2008
    i'm not following what <cfset variables.txtNTUsername = "username valid is here"/> is.

    where is variables.txt coming from.

    sorry i'm having a rough day with this stuff, but thanks for the help
    Participating Frequently
    June 24, 2008
    hum,

    it would be something of the type?

    <cfquery name="getPermissions" datasource="SiteAdmin">
    SELECT NTUsername, LASNav, WWWNav, EngNav, Control
    FROM WWWAdminTable
    WHERE NTUsername = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.NTUsername#">
    <cfquery>

    <cfif getPermissions.recordCount GT 0>
    it's ok :-D
    <cfelse>
    no ok! :-(
    </cfif>