cspitzig
06-29-2004, 09:05 PM
I really need some help.
I have an assignment due tomorrow but I keep getting a "variable" not defined error.
I have to take an SQL "update" page and convert it to an SQL "insert" page, but I keep getting an error.
could someone please help me pinpoint the problem
I am so over my head here!
Colleen
<HTML>
<HEAD>
<TITLE>assignment4_insert
</TITLE>
</HEAD>
<CFOUTPUT>
<!--- initialize variables if form has not been posted --->
<cfif NOT IsDefined("FORM.Task")>
<CFQUERY Name="q_products" Datasource="web_catalogue">
SELECT products.*, Category.Category FROM products, category
<!-- WHERE products.product_ID = #product_ID#
AND products.category_ID=category.category_ID-->
</CFQUERY>
<!--- must set to category ID not category name --->
<cfset FORM.Category = q_products.category_id>
<cfset FORM.Product_Name = q_products.Product_Name>
<cfset FORM.Product_Description = q_products.Product_Description>
<cfset FORM.In_Stock = q_products.In_Stock>
<cfset FORM.Availability = q_products.Availability>
</cfif>
<!--- check for the form post and do some form data validation --->
<cfif IsDefined("FORM.TASK")>
<cfif NOT IsDefined("FORM.In_Stock")>
<cfset FORM.In_Stock="">
</cfif>
<!--- set a variable to hold the error message if needed --->
<cfset errMsg = "">
<!--- ensure the category has been entered --->
<cfif NOT Len(FORM.Category)>
<cfset errMsg = errMsg & "<li>Please enter the Category.">
</cfif>
<!--- ensure the product name has been entered --->
<cfif NOT Len(FORM.Product_Name)>
<cfset errMsg = errMsg & "<li>Please enter the Product Name.">
</cfif>
<!--- ensure the product description has been entered --->
<cfif NOT Len(FORM.Product_Description)>
<cfset errMsg = errMsg & "<li>Please enter the Product Description.">
</cfif>
<!--- ensure the In stock has been entered --->
<cfif NOT Len(FORM.In_Stock)>
<cfset errMsg = errMsg & "<li>Please indicate if item is in stock or not.">
</cfif>
<!--- ensure the Availability has been entered --->
<cfif NOT Len(FORM.Availability)>
<cfset errMsg = errMsg & "<li>Please enter the Availability date.">
<!--- if the date was entered ensure it is a valid date --->
<cfelseif Len(FORM.Availability) AND NOT IsDate(FORM.Availability)>
<cfset errMsg = errMsg & "<li>The Availability date is not a valid date.">
</cfif>
<!--- if errors are found - add a begginning to the error message --->
<cfif Len(errMsg)>
<cfset errMsg = "<b>The following error(s) occurred:</b><br>" & errMsg>
<!--- put the <cfelse> here and moved the closing </cfif> after the cflocation below - IF error add to messege ELSE run the query and re-locate --->
<cfelse>
<CFQUERY DATASOURCE="web_catalogue">
INSERT INTO Products (Category, Product_Name, Product_Description, In_Stock, Availability) VALUES '#FORM.Category#,' '#FORM.Product_Name#',
'#FORM.Product_Description#', '#FORM.In_Stock#,' '#FORM.Availability#'
</CFQUERY>
<CFLOCATION URL="assignment4-1.cfm">
</cfif>
</CFIF>
<BODY>
<CFQUERY Name="listing" Datasource="web_catalogue">
SELECT * FROM Category
</CFQUERY>
<!--- SHOW ERRORS IF ANY --->
<cfif IsDefined("errMsg") AND Len(errMsg)>
#ErrMsg#
</cfif>
<DIV ALIGN="CENTER">
<TABLE CELLPADDING="3" CELLSPACING="1">
<TR>
<TD BGCOLOR="WHITE" COLSPAN="10" ALIGN="CENTER"><FONT FACE="ARIAL" SIZE="4"><B></B></TD>
</TR>
<FORM ACTION="assignment4_update.cfm" METHOD="POST">
<TR>
<TD BGCOLOR="CDD1E1"><FONT FACE="ARIAL" SIZE="2">
<SELECT NAME="Category">
<OPTION VALUE="">Select Category
<CFLOOP query="listing">
<OPTION VALUE="#Category_ID#" <cfif FORM.Category eq Category_ID>Selected</cfif>>#Category#</OPTION>
</CFLOOP>
</SELECT>
</TD>
</TR>
<TR>
<TD BGCOLOR="D2D3E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Product_Name" VALUE="#FORM.Product_Name#"></TD>
</TR>
<TR>
<TD BGCOLOR="D7D5E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Product_Description" VALUE="#FORM.Product_Description#"></TD>
</TR>
<TR>
<TD BGCOLOR="DCD7E2"><FONT FACE="ARIAL" SIZE="2">
<INPUT TYPE="radio" NAME="In_Stock" VALUE="0" <cfif FORM.In_Stock eq 0></cfif>>Yes
<INPUT TYPE="radio" NAME="In_Stock" VALUE="1" <cfif FORM.In_Stock eq 1></cfif>>No
</TD>
</TR>
<TR>
<TD BGCOLOR="E1D8E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Availability" VALUE="#FORM.Availability#"></TD>
</TR>
<TR>
<TD BGCOLOR="E1D8E2"><FONT FACE="ARIAL" SIZE="2">
<INPUT TYPE="submit" NAME="TASK" VALUE="Click Here to Update The Record">
</TD>
</TR>
</FORM>
</TABLE>
</DIV>
</CFOUTPUT>
</BODY>
</HTML>
[/size]
I have an assignment due tomorrow but I keep getting a "variable" not defined error.
I have to take an SQL "update" page and convert it to an SQL "insert" page, but I keep getting an error.
could someone please help me pinpoint the problem
I am so over my head here!
Colleen
<HTML>
<HEAD>
<TITLE>assignment4_insert
</TITLE>
</HEAD>
<CFOUTPUT>
<!--- initialize variables if form has not been posted --->
<cfif NOT IsDefined("FORM.Task")>
<CFQUERY Name="q_products" Datasource="web_catalogue">
SELECT products.*, Category.Category FROM products, category
<!-- WHERE products.product_ID = #product_ID#
AND products.category_ID=category.category_ID-->
</CFQUERY>
<!--- must set to category ID not category name --->
<cfset FORM.Category = q_products.category_id>
<cfset FORM.Product_Name = q_products.Product_Name>
<cfset FORM.Product_Description = q_products.Product_Description>
<cfset FORM.In_Stock = q_products.In_Stock>
<cfset FORM.Availability = q_products.Availability>
</cfif>
<!--- check for the form post and do some form data validation --->
<cfif IsDefined("FORM.TASK")>
<cfif NOT IsDefined("FORM.In_Stock")>
<cfset FORM.In_Stock="">
</cfif>
<!--- set a variable to hold the error message if needed --->
<cfset errMsg = "">
<!--- ensure the category has been entered --->
<cfif NOT Len(FORM.Category)>
<cfset errMsg = errMsg & "<li>Please enter the Category.">
</cfif>
<!--- ensure the product name has been entered --->
<cfif NOT Len(FORM.Product_Name)>
<cfset errMsg = errMsg & "<li>Please enter the Product Name.">
</cfif>
<!--- ensure the product description has been entered --->
<cfif NOT Len(FORM.Product_Description)>
<cfset errMsg = errMsg & "<li>Please enter the Product Description.">
</cfif>
<!--- ensure the In stock has been entered --->
<cfif NOT Len(FORM.In_Stock)>
<cfset errMsg = errMsg & "<li>Please indicate if item is in stock or not.">
</cfif>
<!--- ensure the Availability has been entered --->
<cfif NOT Len(FORM.Availability)>
<cfset errMsg = errMsg & "<li>Please enter the Availability date.">
<!--- if the date was entered ensure it is a valid date --->
<cfelseif Len(FORM.Availability) AND NOT IsDate(FORM.Availability)>
<cfset errMsg = errMsg & "<li>The Availability date is not a valid date.">
</cfif>
<!--- if errors are found - add a begginning to the error message --->
<cfif Len(errMsg)>
<cfset errMsg = "<b>The following error(s) occurred:</b><br>" & errMsg>
<!--- put the <cfelse> here and moved the closing </cfif> after the cflocation below - IF error add to messege ELSE run the query and re-locate --->
<cfelse>
<CFQUERY DATASOURCE="web_catalogue">
INSERT INTO Products (Category, Product_Name, Product_Description, In_Stock, Availability) VALUES '#FORM.Category#,' '#FORM.Product_Name#',
'#FORM.Product_Description#', '#FORM.In_Stock#,' '#FORM.Availability#'
</CFQUERY>
<CFLOCATION URL="assignment4-1.cfm">
</cfif>
</CFIF>
<BODY>
<CFQUERY Name="listing" Datasource="web_catalogue">
SELECT * FROM Category
</CFQUERY>
<!--- SHOW ERRORS IF ANY --->
<cfif IsDefined("errMsg") AND Len(errMsg)>
#ErrMsg#
</cfif>
<DIV ALIGN="CENTER">
<TABLE CELLPADDING="3" CELLSPACING="1">
<TR>
<TD BGCOLOR="WHITE" COLSPAN="10" ALIGN="CENTER"><FONT FACE="ARIAL" SIZE="4"><B></B></TD>
</TR>
<FORM ACTION="assignment4_update.cfm" METHOD="POST">
<TR>
<TD BGCOLOR="CDD1E1"><FONT FACE="ARIAL" SIZE="2">
<SELECT NAME="Category">
<OPTION VALUE="">Select Category
<CFLOOP query="listing">
<OPTION VALUE="#Category_ID#" <cfif FORM.Category eq Category_ID>Selected</cfif>>#Category#</OPTION>
</CFLOOP>
</SELECT>
</TD>
</TR>
<TR>
<TD BGCOLOR="D2D3E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Product_Name" VALUE="#FORM.Product_Name#"></TD>
</TR>
<TR>
<TD BGCOLOR="D7D5E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Product_Description" VALUE="#FORM.Product_Description#"></TD>
</TR>
<TR>
<TD BGCOLOR="DCD7E2"><FONT FACE="ARIAL" SIZE="2">
<INPUT TYPE="radio" NAME="In_Stock" VALUE="0" <cfif FORM.In_Stock eq 0></cfif>>Yes
<INPUT TYPE="radio" NAME="In_Stock" VALUE="1" <cfif FORM.In_Stock eq 1></cfif>>No
</TD>
</TR>
<TR>
<TD BGCOLOR="E1D8E2"><FONT FACE="ARIAL" SIZE="2"><INPUT TYPE="text" NAME="Availability" VALUE="#FORM.Availability#"></TD>
</TR>
<TR>
<TD BGCOLOR="E1D8E2"><FONT FACE="ARIAL" SIZE="2">
<INPUT TYPE="submit" NAME="TASK" VALUE="Click Here to Update The Record">
</TD>
</TR>
</FORM>
</TABLE>
</DIV>
</CFOUTPUT>
</BODY>
</HTML>
[/size]



