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

Need help with calculations

Status
Not open for further replies.

farscp1

Programmer
Sep 18, 2005
33
US
I have a loop that will insert user course selections. I also want to keep a running sum of the costs for these courses. The course fee is stored in tblCourse.course_fee
which is then multiplied by number of people attending the course, which the users enters a value(no_attending). I keep getting an error message

Code:
	<cfquery name="getFee" datasource="seligins">
		SELECT course_fee
		FROM tblCourse
		WHERE course_id = '#Form.course_id#'
	</cfquery>

	<!--- Insert fees details --->
	<cfset thisList = "#Form.course_id#">
	<cfloop list = "#thisList#" index="nthisList">
		<cfquery name="insertFee" datasource="seligins">
			  INSERT INTO tblAttendee_registration
					(subtotal) 
			  VALUES
					(getFee.course_fee * #Form.no_attending#)
		</cfquery>
	</cfloop>

The error message is:


The name 'course_fee' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.


Thanks for your help.
 
you're trying to use a value from the previous query so you'll have to put hash marks around it.

getFee.course_fee * #Form.no_attending#)

should be

#getFee.course_fee# * #Form.no_attending#)

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Hi a few things, first of all you use form.course_id to retrieve the course_you then set the same course id to another variable:
Code:
<cfset thisList = "#Form.course_id#">
you do not need the quotes or pound signs as form.course_id is a variable and not a string containing a variable.

Code:
<cfset thisList = Form.course_id >
Secondly this step is redundant you could use it directly in your list instead of setting it to another variable(assuming that you do actually want to loop over the course id and this is not a mistake as you do not reference nthisList anywwhere):

Code:
<cfloop list = "#Form.course_id#" index="nthisList">

I think your db is complaining because of this line
Code:
(getFee.course_fee * #Form.no_attending#)
it doesn't like the reference to getFee.course-fee, Try:

Code:
<cfquery name="getFee" datasource="seligins">
    SELECT course_fee
    FROM tblCourse
    WHERE course_id = '#Form.course_id#'
</cfquery>

<cfset newSubTotal = getFee.course_fee * Form.no_attending >
        
<cfquery name="insertFee" datasource="actualDSN">
   INSERT INTO tblAttendee_registration
   (subtotal)
    VALUES
   (newSubTotal)
 </cfquery>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top