Time:
Scotland: Sat, 12:38 am
Rhode Island: Fri, 7:38 pm
Florida: Fri, 7:38 pm
New Mexico: Fri, 5:38 pm
California: Fri, 4:38 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : Discuss Newbie Problem


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]

Vincent Puglia
06-30-2004, 05:39 PM
Hi Colleen & welcome to the City that is almost always in over its head :)

Since you didn't state which line and/or variable was producing the error, I cannot say with any certitude what the problem is. However, you might want to look at the way you are separating your values (quote/comma)

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#'


Vinny

cspitzig
06-30-2004, 05:53 PM
Hi Vinny

thanks, I made that correction. I have been re working the document and I passed the "variable" Category from the URL in the calling page and now I get the error variable "Product_Name" is undefined.

Can you tell me where I can read up on the undefined error. I have the variables declared in a number of way, but I am obviously missing a key element here!

Colleen

Vincent Puglia
06-30-2004, 06:26 PM
Hi Colleen,

Offhand, I can't think of a link and/or book that explicitly defines/discusses script errors -- most people I know simply picked the knowledge up by writing buggy scripts :)

Undefined errors usually imply that a variable either has been improperly declared or never been properly defined. (remember, definition and declaration are 2 different things).

I'm assuming your error is popping up with the insert:

INSERT INTO Products (Category, Product_Name, .....

where is the variable defined? You can try placing an alert somewhere just ahead of the offending line, something like:

<script type='text/javascript'>
alert(Product_Name)
</script>

Vinny