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

Losing ID after CFELSE

Status
Not open for further replies.

RikForgo

Programmer
Jul 31, 2002
59
0
0
US
I have a form/action page set that allows users to create a record for past work weeks. The premise is simple. If they are the first one to create a work week record, fine it is created and then a CFLOCATION tag takes them to a Task page where they can add the tasks they hace completed. It works fine.

Now, I have CFIF logic built in that determines whether someone has created a record for that week already. If someone has, they get a message alerting them and offering them a chance to add another task to that week's data, or to view a list of all the weeks submitted. This is where my problem starts.

Everything works right up until the CFELSE statement. I can't get the ID to pass to the URL link after the CFELSE. I want the ID to pass so the task page can query the proper record and allow the user to input against that ID. But it won't pass, and I'm confused as to why not.

Here's my code for the action page:

----------------------------

<!--- param values --->
<cfparam name="report_id" default="report_id">

<!-- The CFSet will create an input from for the marker field in the 'Report' table that can be queried for the insertion of the tasks. -->
<CFSET temp = Rand()>

<CFQUERY NAME="CheckForm" DATASOURCE="#REQUEST.DataSource#">
select period
from report
where period = '#form.period#'
</CFQUERY>

<!-- The CheckForm query uses '#form.period#' to determine whether a record has been created for a given period. If one has, the validation CFIF statement directs the user to a page with a choice of 'Add tasking' or 'View List.' -->

<CFIF CheckForm.RecordCount EQ "0">

<!--- Use CFQUERY to insert all html form field values into the Report table --->
<CFQUERY DATASOURCE="#REQUEST.DataSource#">
INSERT INTO report
(period, marker)

VALUES
('#Form.period#', '#temp#')
</CFQUERY>

<cfquery name="qGetitBack" DATASOURCE="#REQUEST.DataSource#">
select report_id
from report
where marker = '#temp#'
</CFQUERY>


<CFLOCATION URL="t3i_add_form_task.cfm?report_id=#qGetitBack.report_id#">

<CFELSE>

A Weekly Report for this Period has already been created. You cannot create another record for this Period, but you can add your taskings to this one. <br><br>

Would you like to:<br><br><CFOUTPUT>
<a href="t3i_add_form_task.cfm?report_id=#report_id#">Add Tasking:</a></CFOUTPUT>
<br><br>
<a href="..\report_list.cfm"><font color="##000099">View Report:</font></a>
</CFIF>

-----------------------

Any help is appreciated.
 
hi,

it looks like the query that gives you the #report_id# variable is after the cfif. the report_id is not created after the else, because the query was not performed unless checkform.recordcount EQ 0. maybe the qGetitBack query should be performed after the cfelse as well, then the #report_id# would be available to you for the link.
 
Well, there was some progress. It's actually sending me back to the form page, but the ID still doesn't go with it. FWIW, I added the qGetitBack query after the cfelse. It moves me along to the form page, but it can't find the ID. The form page code is below, followed by the error message if that's helpful (I hope).

----------
task_form_task.cfm

<!--- param your query vars, they should be present in either the form or url scope--->
<cfparam name="report_id" default="report_id">
<cfparam name="period" default="period">

<CFQUERY NAME="GetCategories" DATASOURCE="#REQUEST.DataSource#">
SELECT task_cat
FROM task_cats
order by task_cat
</CFQUERY>

<CFQUERY DATASOURCE="t3i" name="GetPeriod">
SELECT period
FROM report
WHERE report_id = #report_id#;
</cfquery>

<html>
<head>
<title>T3I Weekly Report Utility: Step 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p class="mediumheading">T3I Weekly Report Utility:<br>
<strong>Submit Tasks for <em><CFOUTPUT QUERY="GetPeriod">#period#</CFOUTPUT></em> </strong></p>
<form action="t3i_add_action_task.cfm" method="post">


<table width="487">
<tr>
<td width="479" class="mediumheading_sm">Task Category:</td>
</tr>
<tr>
<td class="mediumheading_sm"><select name="project_cat">
<CFOUTPUT QUERY="GetCategories">
<option value="#GetCategories.task_cat#">
#GetCategories.task_cat# </CFOUTPUT> </select></td>
</tr>
<tr>
<td class="mediumheading_sm">Task:</td>
</tr>
<tr>
<td class="mediumheading_sm"><textarea name="task" cols="55" rows="6" wrap="VIRTUAL" id="task"></textarea></td>
</tr>
<tr>
<td class="mediumheading_sm"><input name="report_id" type="hidden" value="<CFOUTPUT>#report_id#</CFOUTPUT>"></td>
</tr>
<tr>
<td class="mediumheading_sm" height="57"> <input name="submit" type="Submit" id="submit" value=" Submit ">
</td>
</tr>
</table>
</form>
</body>
</html>

----------

Error Occurred While Processing Request
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)

[MySQL][ODBC 3.51 Driver][mysqld-3.23.58-nt]You have an error in your SQL syntax near '' at line 3

SQL = "SELECT period FROM report WHERE report_id = ;"
Data Source = "T3I"

The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (11:1) to (11:43) in the template file c:\inetpub\
Date/Time: 04/15/04 10:14:11
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; Dreamweaver MX 6.0.1714)
Remote Address: 127.0.0.1
Query String: report_id=
 
ok, i rethought your process, i think this should work:

Code:
<!--- param values // I would remove this, even if you needed it, it wouldn't work right with that default value, it appears the default value should be numeric anyways--->
<!--- <cfparam name="report_id" default="report_id"> --->

<!-- The CFSet will create an input from for the marker field in the 'Report' table that can be queried for the insertion of the tasks. -->
<CFSET temp = Rand()>
<!--- //Add report_id to your SELECT, so you can call on it after your CFELSE --->
<CFQUERY NAME="CheckForm" DATASOURCE="#REQUEST.DataSource#">
   select period,report_id
   from   report
   where  period = '#form.period#'
 </CFQUERY>

<!-- The CheckForm query uses '#form.period#' to determine whether a record has been created for a given period.  If one has, the validation CFIF statement directs the user to a page with a choice of 'Add tasking' or 'View List.' -->

<CFIF CheckForm.RecordCount EQ "0">
 
<!--- Use CFQUERY to insert all html form field values into the Report table --->
<CFQUERY DATASOURCE="#REQUEST.DataSource#">
    INSERT INTO report
    (period, marker)
    
    VALUES
    ('#Form.period#', '#temp#')
</CFQUERY>

<cfquery name="qGetitBack" DATASOURCE="#REQUEST.DataSource#">
select  report_id
from    report
where   marker = '#temp#'
</CFQUERY>


<CFLOCATION URL="t3i_add_form_task.cfm?report_id=#qGetitBack.report_id#">

<CFELSE>
 
A Weekly Report for this Period has already been created. You cannot create another record for this Period, but you can add your taskings to this one. <br><br>

Would you like to:<br><br><CFOUTPUT>
<!--- //Use the report id value from your first query to pass to the task page --->
<a href="t3i_add_form_task.cfm?report_id=#CheckForm.report_id#">Add Tasking:</a></CFOUTPUT>
<br><br>
<a href="..\report_list.cfm"><font color="##000099">View Report:</font></a>
</CFIF>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top