EasyCFM.COM ColdFusion Forums / Coding Help! / Forms and Queries

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Forms and Queries

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

busydog
08-23-2003 @ 6:29 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 5
Joined: Aug 2003

I have the query below, and in order for it to select the right data I need it to include selected data from the form variable provided. The variable has been declared/actioned/posted in the previous template but I keep getting the error message " ELEMENT #FORM.studentSelect# is undefined in FORM"

<CFQUERY NAME="IndivNumberHelp" DATASOURCE="#datasource#">
          SELECT COUNT(studentAction)AS Indiv_Help
          FROM ActionLog, Students     
          WHERE Students.id=#FORM.studentSelect#
          AND Students.id=ActionLog.studentID
          AND studentAction=1
          <CFIF #FORM.Time# eq 1>
               AND ActionLog.timestamp>=#todaySec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 2>
               AND ActionLog.timestamp>=#weekSec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 3>
               AND ActionLog.timestamp>=#monthSec#
               AND ActionLog.timestamp<=#now#
          </CFIF>
</CFQUERY>

Where am I going wrong? I'm sure that this is something simple and obvious but I'm new to this CFML game and need all the help I can get!

Thank you Thank you!

Redmanz
08-23-2003 @ 8:29 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 411
Joined: Oct 2002

Is the bad form field a checkbox or radio button?

If it is than you need to cfparam it. if a radio button or checkbox is not checked there is no value sent period almost as if it never existed in the first place so if your user doesn't select anything and there is a statement looking for a value, in essence the value doesn't exist period as it was not used........

Hope this helps

Coldfusion Applications designed for learning available:
http://www.ideaz.ca/rez_productions/active_projects/index.htm

busydog
08-23-2003 @ 9:10 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 5
Joined: Aug 2003

The bad form field is a dynamically populated select box...not sure how CFPARAM will work with this...

Redmanz
08-23-2003 @ 9:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 411
Joined: Oct 2002

than it would help to see the query and the select field that is actually submitting to the action.......

Coldfusion Applications designed for learning available:
http://www.ideaz.ca/rez_productions/active_projects/index.htm

busydog
08-23-2003 @ 10:02 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 5
Joined: Aug 2003

Here's the query etc for the form whose data I'm trying to get into the query
<CFQUERY NAME="GetStudents" DATASOURCE="#datasource#">
     SELECT id,lastName,firstName
     FROM Students
</CFQUERY>

<FORM NAME="studentSelect" METHOD="POST">
     <SELECT NAME="studentSelect" onChange="UpdateSettings()">
     <OPTION>Please Select</OPTION>
     <CFLOOP QUERY="GetStudents">
     <OPTION VALUE="#id#"<CFIF pStudentS eq "#id#">SELECTED</CFIF>>#lastName# #firstName#</OPTION>                    
     </CFLOOP>
     </SELECT>
     <CFIF pStudentS gt 0>
          <CFINCLUDE TEMPLATE="Time.cfm">
     </CFIF>
</FORM>     
</CFOUTPUT>

...it works in the template when I don't use other forms within queries but when I have another query on the page using a different form that has been manually filled I get the error message for the query I am not executing.....


<CFQUERY NAME="IndivNumberHelp" DATASOURCE="#datasource#">
          SELECT COUNT(studentAction)AS Indiv_Help
          FROM ActionLog, Students     
          WHERE Students.id=#FORM.studentSelect#
          AND Students.id=ActionLog.studentID
          AND studentAction=1
          <CFIF #FORM.Time# eq 1>
               AND ActionLog.timestamp>=#todaySec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 2>
               AND ActionLog.timestamp>=#weekSec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 3>
               AND ActionLog.timestamp>=#monthSec#
               AND ActionLog.timestamp<=#now#
          </CFIF>
</CFQUERY>

<CFQUERY NAME="LabNumberHelp" DATASOURCE="#datasource#">     
          SELECT COUNT(studentAction)AS Lab_Help
          FROM ActionLog, Students, StudentGroups     
          WHERE studentAction=1          
          AND StudentGroups.groupID=#FORM.LabChoices#
          AND Students.id=StudentGroups.studentID
          AND ActionLog.studentID=StudentGroups.studentID
          <CFIF #FORM.Time# eq 1>
               AND ActionLog.timestamp>=#todaySec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 2>
               AND ActionLog.timestamp>=#weekSec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 3>
               AND ActionLog.timestamp>=#monthSec#
               AND ActionLog.timestamp<=#now#
          </CFIF>
     
</CFQUERY>

<CFQUERY NAME="ClassNumberHelp" DATASOURCE="#datasource#">
          SELECT COUNT(studentAction) AS Class_Help
          FROM ActionLog
          WHERE studentAction=1          
          <CFIF #FORM.Time# eq 1>
               AND ActionLog.timestamp>=#todaySec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 2>
               AND ActionLog.timestamp>=#weekSec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 3>
               AND ActionLog.timestamp>=#monthSec#
               AND ActionLog.timestamp<=#now#
          </CFIF>
</CFQUERY>

<CFQUERY NAME="AvgClassNumberHelp" DATASOURCE="#datasource#">
          SELECT COUNT(studentAction) AS Avg_Class_Help
          FROM ActionLog
          WHERE studentAction=1
          <CFIF #FORM.Time# eq 1>
               AND ActionLog.timestamp>=#todaySec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 2>
               AND ActionLog.timestamp>=#weekSec#
               AND ActionLog.timestamp<=#now#
          <CFELSEIF #FORM.Time# eq 3>
               AND ActionLog.timestamp>=#monthSec#
               AND ActionLog.timestamp<=#now#
          </CFIF>

</CFQUERY>

<CFIF #FORM.helpChoices# eq 1>
     <CFOUTPUT QUERY="IndivNumberHelp">
          <CFIF Indiv_Help eq 0>
               <CENTER><TD>You have not asked for help.</TD></CENTER>
          <CFELSEIF Indiv_Help gt 0>
               <CENTER><TD>You have asked for help #Indiv_Help# times.</TD></CENTER>
          </CFIF>
     </CFOUTPUT>

<CFELSEIF #FORM.helpChoices# eq 2>
     <CFOUTPUT QUERY="LabNumberHelp">
          <CFIF Lab_Help eq 0>
               <CENTER><TD>There have been no help requests from this lab group</TD></CENTER>
          <CFELSEIF Lab_Help gt 0>
               <CENTER><TD>There have been #Lab_Help# help requests from this lab group</TD></CENTER>
          </CFIF>
     </CFOUTPUT>          
<CFELSEIF #FORM.helpChoices# eq 3>
     <CFOUTPUT QUERY="ClassNumberHelp">
          <CFIF Class_Help eq 0>
               <CENTER><TD>There have been no help requests from the class</TD></CENTER>
          <CFELSEIF Class_Help gt 0>
               <CENTER><TD>There have been #Class_Help# help requests from this lab group</TD></CENTER>                    
          </CFIF>
     </CFOUTPUT>
<CFELSEIF #FORM.helpChoices# eq 4>     
</CFIF>


Website Designed and Developed by Pablo Varando.