|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Error With My Code-Please Help!
The Code
<cfif NOT isDefined("Form.Material") OR NOT isDefined("Form.Mfg") OR NOT isDefined("Form.IssueDate") OR NOT isDefined("Form.UnitId") OR NOT isDefined("Form.materialId")> <cfoutput> <a href="newMSDS.cfm">Sorry, please click here to go back and enter the required information.</a> </cfoutput> <cfelse> <cfquery name="InsertMaterials" datasource="****"> SELECT material FROM material WHERE material='#Form.Material#' </cfquery> <cfif InsertMaterials.recordCount GT "0"> <cfoutput>Sorry that material already exists.</cfoutput> </cfif> <cfquery name="InsertMaterials" datasource="****"> INSERT INTO dbo.Material ( Material, Mfg, IssueDate, ShelfLife ) VALUES ( '#Form.Material#', '#Form.Mfg#', '#DateFormat(Form.IssueDate,"mm/dd/yyyy")#', '#Form.ShelfLife#' ) </cfquery> <cfquery name="getMaterialId" datasource="****"> SELECT materialId FROM material WHERE material = '#Form.Material#' AND mfg = '#Form.Mfg#'; </cfquery> <cfoutput> <cfloop list="#Form.UnitId#" index="currentUnitId"> <cfquery name="UnitId" datasource="MSDS"> INSERT INTO dbo.UnitMaterials ( UnitId, MaterialId ) VALUES ( '#currentUnitId#', '#getMaterialId.MaterialId#' ) </cfquery> </cfloop> </cfoutput> <cflocation url="materialDetail.cfm?MaterialId=#getMaterialId.MaterialId#"> </cfif> My problem is that when a user enters in the same material name, it allows them to rather than letting them know this material already exists. When I try to put a <cfelseif> tag for the record count, it does not get recognized and an error pops up. Need help thanks! |
|
#2
|
|||
|
|||
|
Well, what do you want to happen if the query to check the material shows that the same material already exists? Abort the request? Redisplay the form? Not do the insert?
If you just want it to show the error message and skip the insert, this should work: Code:
<cfif NOT isDefined("Form.Material") OR NOT isDefined("Form.Mfg") OR NOT isDefined("Form.IssueDate") OR NOT isDefined("Form.UnitId") OR NOT isDefined("Form.materialId")>
<cfoutput>
<a href="newMSDS.cfm">Sorry, please click here to go back and enter the required information.</a>
</cfoutput>
<cfelse>
<cfquery name="InsertMaterials" datasource="****">
SELECT material
FROM material
WHERE material='#Form.Material#'
</cfquery>
<cfif InsertMaterials.recordCount GT "0">
<cfoutput>Sorry that material already exists.</cfoutput>
<cfelse>
<cfquery name="InsertMaterials" datasource="****">
INSERT INTO dbo.Material (
Material,
Mfg,
IssueDate,
ShelfLife
)
VALUES (
'#Form.Material#',
'#Form.Mfg#',
'#DateFormat(Form.IssueDate,"mm/dd/yyyy")#',
'#Form.ShelfLife#'
)
</cfquery>
<cfquery name="getMaterialId" datasource="****">
SELECT materialId
FROM material
WHERE material = '#Form.Material#' AND mfg = '#Form.Mfg#';
</cfquery>
<cfoutput>
<cfloop list="#Form.UnitId#" index="currentUnitId">
<cfquery name="UnitId" datasource="MSDS">
INSERT INTO dbo.UnitMaterials (
UnitId,
MaterialId
)
VALUES (
'#currentUnitId#',
'#getMaterialId.MaterialId#'
)
</cfquery>
</cfloop>
</cfoutput>
<cflocation url="materialDetail.cfm?MaterialId=#getMaterialId.MaterialId#">
</cfif>
</cfif>
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Thanks man that helped a lot!
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Error With My Code-Please Help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|