it looks to me like the problem may be here in the cfif statment Change this <cfif IsDefined("FORM.USER_NAME_NAME")> Code (markup): To this <cfif IsDefined("FORM.USERNAME_NAME")> Code (markup): Sorry this may be myfault, I think I wrote it the wrong in the first place. Hope this works
Ok great. So if I understand correctly, I set this in the login process: <cfset session.userid = #form.username_name#> Code (markup): So, on any page in my site (preferably the top right corner), I can include something like: <cfif structKeyExists(session, "USERID") AND session.USERID NEQ ""> Welcome #session.userid#! <cfelse> Login below, or <a href="register.cfm">register</a>! ... login form code... </Cfif> Code (markup): If the user is not logged in, it will simply say "Login below or register!", with a login form beneath. If the user IS logged in, it'll say... for me... Welcome Nick! correct? Also, how do I pull other user data from the database? For instance, if I have a "favorite recipe" field in my TBLUSER... and i want to show the logged in user his/her favorite recipe... would it simply be... #session.fav_recipe# Code (markup): Or, would I have to include a query... such as: <cfquery name="favrecipe" datasource="mydatabase"> SELECT USER_NAME_NAME, FAV_RECIPE FROM TBLUSER WHERE USER_NAME_NAME = #session.userid# </cfquery> <cfset session.favrecipe = #favrecipe.FAV_RECIPE#> Your favorite recipe is #session.favrecipe#! Code (markup): This seems like a hassle... is it necessary?
Yes you do have to do query because the session variables will expire. If you dont want to run a query to retrive the fav recipe then one option is to store it as a cookie on the client machine. This is not prefered because not everyones computer will let you store a cookie. also if they delete their cookies then the info is lost. So just run the query when they log in. put the query right on login action page and set the session.favrecipe variable right away.
Back to the registration page... I run a check on the action page to make sure the username isn't already taken. It works fine. Then I tried doing the same thing with the email address. But, it doesn't work. Regardless if the email address is already taken, it allows the new user to register with it! I wonder if it's a problem with the @ symbol. Here is my code for the action page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <cfif isdefined("form.upload_now")> <cfset maxFileSize = (150 * 1024)> <cfset serverFileName = ""> <cfset clientFileName = ""> <cfset wasFileDeleted = false> <cfif len(trim(form.ul_path))> <cffile action="upload" filefield="ul_path" destination="#ExpandPath("/user_uploads")#" accept="image/jpeg, image/gif, image/jpg, image/svg, image/pjpeg, image/pjpg, image/png, image/x-png" nameconflict="makeunique"> <cfset serverFileName = CFFILE.serverFile> <cfset clientFileName = CFFILE.clientFile> <cfif CFFILE.fileSize GT maxFileSize> <cffile action="delete" file="#CFFILE.serverDirectory#\#CFFILE.serverFile#"> <cfset wasFileDeleted = true> </cfif> </cfif> </cfif> <CFSET Valid = true> <CFSET Error = ""> <cfoutput> <cfif isdefined("form.USER_NAME_NAME")> <cfquery datasource="mydatabase" name="check"> SELECT USER_NAME_NAME FROM TBLUSER WHERE USER_NAME_NAME = '#form.USER_NAME_NAME#' </cfquery> </cfif> </cfoutput> <cfif check.recordcount eq 1> <CFSET Valid = False> <cfelse> </cfif> <CFIF not Valid> This username is taken. <A HREF="javascript:history.go(-1)"><br>Click Here To Return</A> <cfabort> <CFELSE> <CFSET Valid2 = true> <cfoutput> <cfif isdefined("form.EMAIL")> <cfset v = #form.EMAIL#> <cfquery datasource="mydatabase" name="check2"> SELECT * FROM TBLUSER WHERE EMAIL = '#v#' </cfquery> <cfset v ="#check2.EMAIL#"> </cfif> </cfoutput> <cfif check2.recordcount eq 1> <CFSET Valid2 = False> <cfelse> </cfif> <CFIF not Valid2> This email address is already registered! Please click <a href="forgotten_password.cfm">here</a> to retrieve your password. <A HREF="javascript:history.go(-1)"><br>Click Here To Return</A> <cfabort> <CFELSE> <cfif wasFileDeleted> <p>Sorry your file is too big! Hit "back" on your browser, and please try again.</p> <cfelse> <CFQUERY DATASOURCE="mydatabase" NAME="TBLUSER"> INSERT INTO TBLUSER(USER_NAME_NAME, USER_PASS_PASS, SERVER_FILE_NAME, CLIENT_FILE_NAME, EMAIL, CONFIRMED, USER_FIRST_NAME, USER_LAST_NAME, USER_GENDER, USER_FAV_RECIPE) VALUES ( <cfqueryparam value="#form.USER_NAME_NAME#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.USER_PASS_PASS#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#serverFileName#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#clientFileName#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.EMAIL#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.CONFIRMED#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.USER_FIRST_NAME#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.USER_LAST_NAME#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.USER_GENDER#" cfsqltype="cf_sql_varchar"> , <cfqueryparam value="#form.USER_FAV_RECIPE#" cfsqltype="cf_sql_varchar"> ) </CFQUERY> Thank you for registering! Please check your email to complete your registration! Or, click <a href="index.cfm">here</a> to go back to the homepage and login! </p> </p> </p> </cfif> </cfif> </cfif> </body> </html> Code (markup):