Hey everyone this is my first post and im very stuck. I am new to web development and am currently undertaking a College course although i cannot get much help off of my lecturer.

My website is a travel agency that allows online bookings. On my home page there is a list of special offers that the user can click on to order. The offers on display are read from a DB however i need the code to verify the user is logged in once they click on the offers link. If they are logged in they will be directed to my offers.cfm page. If the user is not logged in i need an error message to appear alerting them that they are not logged in and need to be to order these offers.

I know that sounds pretty confusing, and i am sorry but this is hard to explain for a newbie lol. I have pasted the code that i have done to display the offers, hopefully this will help.


<cfquery name="tours" datasource="webtoursmj">
SELECT tours.departdate, packages.tourname, packages.packageid, packages.tourlocation, packages.adultprice
FROM packages INNER JOIN tours
ON packages.packageid = tours.packageid;

<cfoutput query="tours">
#tourname# -
#DateFormat (departdate, "d/m/yy")# -
#tourlocation# -
<a href="offers.cfm?id=#packageid#">BOOK NOW</a><br><br>

Hi, I'm new to CF as well but I hope this will be helpful.
Try using Session variables. When the user logs in, create a Session variable for him/her. Then, you may add an if-else statement to enclose the <a> tag such as, <cfif IsDefined("Session.User")> <!-- your statement --> </cfif>


put this inside a file application.cfm in the directory having all your cfm files

<cfapplication  name="appname"
 clientManagement = "yes"
<!--- set initially the userLogin to be false (user hasn't logged in) --->
 <cfif not isDefined("Session.userLogin")>
  <cfset Session.userLogin = false>

this ensures that whenever there is no variable "userLogin" in session
it is defined and its value is false
application.cfm is executed when you request any page in that directory

now inside the code you would actually do the login for the user remember to put

<cfset Session.userLogin = true>

then in you "offers.cfm" page do the following

<cfif Session.userLogin eq true>
 <!-- do things that you want to do --> 
 <!-- put the error message -->