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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFPARAM not working

Status
Not open for further replies.

Shlomo

IS-IT--Management
May 11, 2000
28
US
Is there any reason why a cfparam would indicate that a variable was in existence when in fact it wasn't? <br>I've tried to do a<br>&lt;CFIF #ParameterExists (variable)# IS &quot;no&quot;&gt;&nbsp;&nbsp;&nbsp;after a cfparam for the same variable<br>&lt;cfparam name=&quot;...&quot; default=&quot;&quot;&gt; <br>and the variable has not yet been defined at that point but&nbsp;&nbsp;CF acts as though&nbsp;&nbsp;the variable has been defined.<br>T.I.A.<br>
 
CFPARAM is what is defining the variable, if I understand you correctly.&nbsp;&nbsp;If you're using the &lt;cfparam name=&quot;variable&quot; default=&quot;&quot;&gt; first, #variable# is defined with a null value....<br><br>Try this:<br><br>&lt;cfparam name=&quot;variable&quot; default=&quot;&quot;&gt;<br>&lt;cfif len(variable)&gt;<br>&nbsp;&nbsp;&lt;!--- Code if variable IS NOT NULL ---&gt;<br>&lt;cfelse&gt;<br>&nbsp;&nbsp;&lt;!--- Code if variable IS NULL ---&gt;<br>&lt;/cfif&gt;<br><br>I prefer to define a default value (usually null) first, then check for a non-null value.&nbsp;&nbsp;It cuts down on errors..
 
CF says that it wasn't able to determine the value of the NULL parameter:<br>&lt;cfparam name=&quot;Session.userid&quot; default=&quot;&quot;&gt;<br>&lt;CFIF len(Session.userid) IS NULL&gt;<br>&lt;cfinclude template=&quot;pass.cfm&quot;&gt;<br>&lt;cfabort&gt;<br>&lt;/cfif&gt;<br>Are these the types of errors yo were referring to?
 
Try writing your code like this:<br><br>&lt;cfparam name=&quot;Session.userid&quot; default=&quot;&quot;&gt;<br>&lt;CFIF len(Session.userid) <b>IS 0</b>&gt;<br>&lt;cfinclude template=&quot;pass.cfm&quot;&gt;<br>&lt;cfabort&gt;<br>&lt;/cfif&gt;<br><br>The len() function checks for the length of the string.&nbsp;&nbsp;The cfparam tag sets your variable to a zero length string (if it isn't already defined), so the above code will run pass.cfm unless Session.userid has already been defined....<br><br>Let me know if this works for you.....
 
Success!!!<br>Thank you very much.<br>It turns out that there were other issues( there is still one more) but that was the main thing.<br>Now it runs, but gives an error while it runs.<br>The reason is that the cfset for the session variable is on the form page so when<br><br>&lt;cfset sessionX= form.X&gt;<br><br>&nbsp;since the form has not been processed it returns an error.&nbsp;&nbsp;But the script still runs since the cfset is not critical at that point and by the time it is the form has been submitted. <br><br>Do you know how to drop a session variable? know when I'm testing I need to chanse the variable to get moivng.<br>Thank you again.<br><br><br><br>
 
OK!!! <br>All working,now.&nbsp;&nbsp;Just needed some fancy footwork with cfparam and cfif.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top