EasyCFM.COM ColdFusion Forums / Coding Help! / syntactically valid variable name ???

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: syntactically valid variable name ???

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

egiblock
10-07-2003 @ 9:28 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 214
Joined: Mar 2003

i have a form on one page

<form>
<input type="text" name="cat_num1" size=5 id="cat_num1">
blah.blah.blah
</form>


and then on the form action page i have the following:


<cfif (isDefined(Trim(#cat_num1#)))
<cfquery name="insertcomment" datasource="chconnection">

INSERT INTO tbl_products blahblahblah
VALUES blahblahblah
     </cfquery>
<cfset add_count = add_count + 1>


and now i am getting the following error message:


An error occurred while evaluating the expression:

isDefined(trim(cat_num1))

Error near line 13, column 6.

Parameter 1 of function IsDefined which is now "1" must be a syntactically valid variable name




can someone help me out with this ??

thanks


Eric Giblock
Owner ~ Sr. Progammer
Web Alterations ~ www.webalterations.com

CJ
10-07-2003 @ 11:19 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

i'm guessing that you put the number 1 in the form field, so #cat_num1# is evaluating to 1 (?)

the way you want to use isDefined() is to enclose the value in quotes.  <cfif isDefined('form.cat_num1')>.  you want it in quotes, because you're not looking to evaluate the value of a variable...you're simply looking for the existence of a variable.

because you didn't enclose it in quotes, you're getting the value of the var.  so your isDefined() is looking for a variable named '1', which is not a syntactically correct variable name (CF variables cannot begin with numbers).

All of this is a moot point, as i don't believe you even want to be using isDefined().  i'm guessing you're just checking to see if the user entered any text, in which case you'd want:

<cfif len(trim(form.cat_num1))>
     <cfquery ...
     </cfquery>
</cfif>



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

egiblock
10-07-2003 @ 12:02 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 214
Joined: Mar 2003

i am just checking to see if anythign was entered into the box.  if it wasn't, skip over it and go to the next field..


Eric Giblock
Owner ~ Sr. Progammer
Web Alterations ~ www.webalterations.com

egiblock
10-07-2003 @ 12:14 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 214
Joined: Mar 2003

it worked....

thanks


Eric Giblock
Owner ~ Sr. Progammer
Web Alterations ~ www.webalterations.com

CJ
10-07-2003 @ 12:24 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

quote:


i am just checking to see if anythign was entered into the box.  if it wasn't, skip over it and go to the next field..



...and just to clarify, that's why you want to use the <cfif len(trim(var))> as opposed to isDefined().  isDefined(), on a form text field, will always be defined.  even if the user entered no text, the variable still exists on the action page.  the value is an empty string, but the variable still exists.



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


Website Designed and Developed by Pablo Varando.