I just want someone to help me debug my code. I am making an application to upload menu items into a database so as to build an online menu out of it. Here is what I have so far: APPLICATION.CFC <cfcomponent output="false"> <cfset this.name="TatasSite"> <!--- Set datasource ---> <cfset ds="Tatas"> <cffunction name="MenuItems" returntype="query" hint="List all menu items"> <cfquery datasource="#ds#" name="menu"> SELECT MenuID, Title FROM Tatas ORDER BY MenuID </cfquery> <cfreturn menu> </cffunction> <cffunction name="get" returntype="query" hint="get menu details"> <cfargument name="MenuID" type="numeric" required="yes" hint="Menu ID"> <cfquery datasource="#ds#" name="MenuItem"> SELECT * FROM Tatas WHERE MenuID=#ARGUMENTS.MenuID# </cfquery> <cfreturn menuItem> </cffunction> <cffunction name="add" returntype="boolean" hint="Add an item"> <cfargument name="Title" type="String" required="yes" hint="Menu Item Title"> <cfargument name="Price" type="numeric" required="no" hint="Price"> <cfargument name="TypeID" type="numeric" required="no" hint="Appetizer, Soup, Salad, Sandwich"> <cfargument name="MealID" type="numeric" required="no" hint="Lunch Or Dinner"> <cfargument name="New" type="boolean" required="yes"> <cfargument name="Spicy" type="boolean" required="yes"> <cfargument name="Detail" type="string" required="yes"> <cfargument name="LanguageID" type="numeric" required="yes"> <cfargument name="SpecialtyID" type="numeric" required="no"> <cfargument name="PicPath" type="string" required="no" hint="Picture of Item"> <!--- Insert Item ---> <cfquery datasource="#ds#"> INSERT INTO Tatas (Title, Price, MealID, New, Spicy, Detail, LanguageID, SpecialtyID, PicPath VALUES('#Trim(ARGUMENTS.Title)#', '#ARGUMENTS.Price#', '#ARGUMENTS.TypeID#', '#ARGUMENTS.MealID#', '#ARGUMENTS.New#', '#ARGUMENTS.Spicy#', '#Trim(ARGUMENTS.Deatil)#', '#ARGUMENTS.LanguageID#', '#ARGUMENTS.SpecialtyID#', '#Trim(FORM.PicPath)#') </cfquery> <cfreturn true> </cffunction> <cffunction name="Update" returntype="boolean" hint="Update menu"> <cfargument name="MenuID" type="numeric" required="yes"> <cfargument name="Title" type="String" required="yes" hint="Menu Item Title"> <cfargument name="Price" type="numeric" required="no" hint="Price"> <cfargument name="TypeID" type="numeric" required="no" hint="Appetizer, Soup, Salad, Sandwich"> <cfargument name="MealID" type="numeric" required="no" hint="Lunch Or Dinner"> <cfargument name="New" type="boolean" required="yes"> <cfargument name="Spicy" type="boolean" required="yes"> <cfargument name="Detail" type="string" required="yes"> <cfargument name="LanguageID" type="numeric" required="yes"> <cfargument name="SpecialtyID" type="numeric" required="no"> <cfargument name="PicPath" type="string" required="no" hint="Picture of Item"> <cfquery datasource="#ds#"> UPDATE Tatas SET Title='#Trim(ARGUMENTS.Title)#', Price=#ARGUMENTS.Price#, TypeID=#ARGUMENTS.TypeID#, MealID=#ARGUMENTS.MealID#, New=#ARGUMENTS.New#, Spicy=#ARGUMENTS.Spicy#, Detail='#Trim(ARGUMENTS.Detail)#', LanguageID=#ARGUMENTS.LanguageID#, SpecialtyID=#ARGUMENTS.SpecialtyID#, PicPath='#Trim(ARGUMENTS.PicPath)#' WHERE MenuID=#ARGUMENTS.MenuID# </cfquery> <cfreturn true> </cffunction> <cffunction name="delete" returntype="boolean" hint="delete an item"> <cfargument name="MenuID" type="numeric" required="yes" hint="Menu ID"> <cfquery datasource="#ds#"> DELETE DROM Tatas WHERE MenuID=#ARGUMENTS.MenuID# </cfquery> <cfreturn true> </cffunction> <cffunction name="type" returntype="query"> <cfquery datasource="#ds#" name="type"> SELECT TypeID, Type FROM Type ORDER BY TypeID </cfquery> <cfreturn type> </cffunction> <cffunction name="meal" returntype="query"> <cfquery datasource="#ds#" name="meal"> SELECT MealID, Meal FROM Meal ORDER BY MealID </cfquery> <cfreturn meal> </cffunction> <cffunction name="Language" returntype="query"> <cfquery datasource="#ds#" name="Language"> SELECT LanguageID, Language FROM Language ORDER BY LanguageID </cfquery> <cfreturn language> </cffunction> <cffunction name="Specialty" returntype="query"> <cfquery datasource="#ds#" name="Specialty"> SELECT SpecialtyID, Specialty FROM Specialty ORDER BY SpecialtyID </cfquery> <cfreturn Specialty> </cffunction> </cfcomponent> XFormEdit.cfm <cfset EditMode=IsDefined("URL.MenuID")> <cfif EditMode> <cfinvoke component="Application" method="get" MenuID="#URL.MenuID#" returnvariable="menuItem"> <cfset Title=Trim(MenuItem.Title)> <cfset Price=Int(MenuItem.Price)> <cfset TypeID=MenuItem.TypeID> <cfset MealID=MenuItem.MealID> <cfset New=MenuItem.New> <cfset Spicy=MenuItem.Spicy> <cfset Detail=Trim(MenuItem.Detail)> <!---<cfset Language=MenuItem.Language> ---> <!---<cfset Specialty=MenuItem.Specialty> ---> <cfset PicPath=Trim(MenuItem.PicPath)> <cfset FormTitle="Update Menu"> <cfset BtnText="Update"> <cfelse> <cfset Title=" "> <cfset Price=" "> <cfset TypeID=" "> <cfset MealID=" "> <cfset New=" "> <cfset Spicy=" "> <cfset Detail=" "> <cfset Language=" "> <cfset Specialty=" "> <cfset PicPath=" "> <cfset FormTitle="Add to Menu"> <cfset BtnText="Add"> </cfif> <cfinvoke component="Application" method="Type" returnvariable="Type"> <cfinvoke component="Application" method="Meal" returnvariable="Meal"> <cfinvoke component="Application" method="Language" returnvariable="Language"> <cfinvoke component="Application" method="Specialty" returnvariable="Specialty"> <!--- HEader ---> <cfinclude template="header.cfm"> <!--- Form ---> <cfform format="xml" action="formdump.cfm" skin="lightgray"> <cfif EditMode> <!--- Embed primary key ---> <cfinput type="hidden" name="MenuID" value="#MenuItem.MenuID#"> </cfif> <cfinput name="title" type="text" label="Title:" value="#Title#" required="yes" message="A title for the plate is required!" validateAt="onSubmit, onServer" size="50" maxlength="100"> <cftextarea name="Detail" label="Description:" cols="40" rows="3" wrap="virtual"><cfoutput>#Detail#</cfoutput></cftextarea> <cfinput name="Price" type="text" label="Price: $" value="#Price#" required="no" message="Price must be a valid dollar amount!" validate="integer" validateAt="onSubmit, onServer" size="10" maxlength="10"> <cfselect name="MealID" label="Meal:" display="Meal" query="Meal"> </cfselect> <cfselect name="TypeID" label="Type of Entree:" query="Type" display="Type"> </cfselect> <cfinput type="radio" label="New:" name="New" value="#New#"> <cfinput type="radio" label="Spicy:" name="Spicy" value="#Spicy#"> <cfselect name="SpecialtyID" label="Specialty:" query="Specialty" display="Specialty"></cfselect> <cfselect name="Language" label="Language:" query="Language" display="Language" /> <cfinput type="submit" name="BtnSubmit" value="#BtnText#"> </cfform> There is a lot of debugging that needs to be done that I just don't know how to do. Help would be very appreciated!
Hi, Debugging implies there is an error or a problem you are trying to solve. But you did not mention what that problem is ... ;-)
oh sorry. Well for one I need all of the select option in the form to have a blank value option. And when I try to access one of the menu items to edit via the URL parameter it throws an error because there is stuff missing from the database so basically everything except the input title needs to be optional and able to be blank.
I don't normally use format="xml" but the usual solution is to generate the list options using cfoutput instead of using the <cfselect query="...">. Then you can add a blank element. <cfselect ..> <option value="(whatever)"> ....</option> <cfoutput query="yourQuery"> <option value="#theValue#">#theText#</option> </cfoutput> </cfselect> Code (markup): Since I am not very familiar with the code, can you be a bit more specific and post the actual error message? It is hard to tell if you are talking about a database error or something else.
BTW, why are you storing all of your functions in the Application.cfc instead of in a separate component?
On the CFSELECT, you can specify the query and also add <option> tags. You can control whether or not the option tags you entered manually appear above or below the query generated option tags with the queryPosition="above|below" property in CFSELECT.
Also when I actually give the form something to edit by means of putting the ID into the url it doesn't work quite right. It gives me only up to the decimal point in the price and won't actually display what the item is in the cfselect option. Like when the menu item is an appetizer it displays the blank option.
Duh! Good point. I totally forget about that. I think you forgot to define a value your select lists.
<cfinput name="title" type="text" label="Title:" value="#Title#" required="yes" message="A title for the entree is required!" validateAt="onSubmit, onServer" size="50" maxlength="100"> <cfinput name="Price" type="text" label="Price:" value="$#Price#" required="no" message="Price must be a valid dollar amount!" validateAt="onSubmit, onServer" size="10" maxlength="10"> <cfselect name="MealID" label="Meal:" display="Meal" query="Meal" queryPosition="below" value="#MealID#"> <option></option> </cfselect> <cfselect name="TypeID" label="Type of Entree:" query="Type" queryPosition="below" value="#TypeID#" display="Type"> <option></option> </cfselect> <cfinput type="checkbox" label="New:" name="New" value="#New#"> <cfinput type="checkbox" label="Spicy:" name="Spicy" value="#Spicy#"> <cfselect name="SpecialtyID" label="Specialty:" query="Specialty" queryPosition="below" value="#SpecialtyID#" display="Specialty"> <option></option> </cfselect> <cfselect name="Language" label="Language:" query="Language" queryPosition="below" value="#LanguageID#" display="Language"> <option></option> </cfselect> <cftextarea name="Detail" label="Description:" cols="40" rows="3" wrap="virtual"><cfoutput>#Detail#</cfoutput></cftextarea> <cfinput type="submit" name="BtnSubmit" value="#BtnText#"> So is that how it should look, because that throws an error message.
So ... what is the error message? We can't see your code / computer ;-) > value="#TypeID#" Though my guess would be the # signs in the value attribute. The "value" and "display" attributes accept a string: the name of the columns to use for the list value and the display text. So remove the # signs http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_r-s_14.html
the error message says: Query column invalid or missing. You must specify the name of a column in the Meal query for the Value attribute of the CFSelect tag. The error occurred in C:\ColdFusion8\wwwroot\Tatas\XFormEdit.cfm: line 59 57 : validateAt="onSubmit, onServer" size="10" maxlength="10"> 58 : 59 : <cfselect name="MealID" label="Meal:" display="Meal" query="Meal" queryPosition="below" value="#MealID#"> 60 : <option></option> 61 : </cfselect>
Did you see my response above about the # signs? That is the problem. You need to remove them. The "value" should be a plain string (ie no # signs) <cfselect value="SomeColumnName" display="OtherColumnName" ....>
Did you select something other than the default in the lists? Cfdump the form scope. What are the results? <cfdump var="#form#"> ... or for method="get" ... <cfdump var="#url#">
But i am trying to edit something from the database via URL parameters and when say one of the items is english the language <select> option shows blank.
I can't see where you're doing that from your code. All I see is something called EditMode where you're just retrieving the data, and language is commented out. Where is your action page ..? BTW, I think you're trying to debug too much at once. That is always takes longer and makes things more difficult. Start with the basics and test one thing at a time. Add a few cfdump's to the top of your action page - before any other code. What are the results? It is hard to help if we can't see the results. <cfdump var="#form#"> ... or for method="get" ... <cfdump var="#url#">