This seems like it should be easy, but man, I'm such a novice at some of this stuff. I feel like I've seen it done, so please bear with me if this is a dumb issue.
I have multiple cfifs set up on the page to filter out specific user groups when a form is submitted. I'd like to use the same cfquery in multiple places. The queries would be updating the same tables using the same form data, the difference would be creating new data or updating data.
EDIT: included more detailed code with common queries on top of the form submission and where I'd like them to render in the code comments
<cfquery name="setnewuserinfo" datasource="db">
INSERT INTO users (name,email)
VALUES ("#form.name#","#form.email#","#form.password#")
</cfquery>
<cfquery name="setnewcustomerinfo" datasource="db">
INSERT INTO customers (name,phone,address,city,state,zip)
VALUES ("#form.customer_name#","#form.phone#","#form.address#","#form.city#","#form.state#",#form.zip#)
</cfquery>
<cfquery name="updateuserinfo" datasource="db">
UPDATE users
SET
name = "#form.name#",
email = "#form.email#"
WHERE email = "#session.userinfo.email#"
</cfquery>
<cfquery name="updatecustomerinfo" datasource="db">
UPDATE customers
SET
name = "#form.customer_name#",
phone = "#form.phone#",
address = "#form.address#",
city = "#form.city#",
state = "#form.state#",
zip = #form.zip#
WHERE id = "#session.customerinfo.id#"
</cfquery>
<cfif IsDefined('form.submit')>
<!--check signin-->
<cfif IsDefined('session.userinfo'>
<cfquery name="checkowner" datasource="db">
SELECT role
FROM users
WHERE id = #session.userinfo.id#
</cfquery>
<cfif checkowner.role EQ "1"><!--is the owner-->
<!--UPDATECUSTOMERINFO-->
<!--UPDATEUSERINFO-->
<cfelse><!--not owner-->
<!--SETNEWCUSTOMERINFO-->
<!--UPDATEUSERINFO-->
</cfif><!--/check owner-->
<cfelse><!--not signed in-->
<!--CHECK DUPLICATE-->
<cfquery name="checkdup" datasource="db" maxrows="1">
SELECT id,email
FROM users
WHERE email = #form.email#
</cfquery>
<cfif checkdup.recordcount GT 0><!--there is a duplicate-->
<cfquery name="checkowner" datasource="db">
SELECT role
FROM users
WHERE id = #session.userinfo.id#
</cfquery>
<cfif checkowner.role EQ "1"><!--is the owner-->
<!--UPDATECUSTOMERINFO-->
<!--UPDATEUSERINFO-->
<cfelse><!--not owner-->
<!--SETNEWCUSTOMERINFO-->
<!--UPDATEUSERINFO-->
</cfif><!--/checkowner-->
<cfelse><!--not a duplicate-->
<!--SETNEWCUSTOMERINFO-->
<!--SETNEWUSERINFO-->
</cfif><!--/checkdup-->
</cfif><!--/check signin-->
</cfif><!--/form submit-->
I'd love to put the queries somewhere and within the <cfif>
say "hey! call this particular query!", but I have no idea how.
Appreciate the help in advance.