Brooke Flame
Brooke Flame

Reputation: 31

CF (If..headerlocation)?

I am trying to make a CF code that will select the row "welcome" from the table "users" where username = #session.username#.

If "welcome" = 1 then i want it to direct the user to /me/index.cfm

I am new at CF, how would this be possible.

Upvotes: 0

Views: 87

Answers (2)

prashant gupta
prashant gupta

Reputation: 19

You can write like :

<cfif welcome EQ 1>
<cflocation url="/me/index.cfm">
</cfif>

Upvotes: 0

duncan
duncan

Reputation: 31912

Firstly you need to do a DB query by the sounds of it:

<cfquery name="getWelcome" datasource="yourDSN">
  SELECT welcome
  FROM users
  WHERE username = <cfqueryparam value="#session.username#" cfsqltype="CF_SQL_VARCHAR"> 
</cfquery>

Then you need to check the value from the query, and also taking into account the fact that the query might not find anything at all.

<cfif NOT getWelcome.recordcount>
<!--- do something, maybe redirect to the login page --->

</cfif>

<cfif getWelcome.welcome EQ 1>
  <cflocation url="/me/index.cfm">
</cfif>

The most important thing here is the use of cfqueryparam to prevent SQL injection.

Upvotes: 4

Related Questions