Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's one way to do it. Reading up on functions in the documentation would be a good start too. <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f5c.html" rel="nofollow">http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f5c.html</a></p> <pre><code>&lt;cffunction name='addClass' returntype='numeric'&gt; &lt;cfargument name='ClassID' type='numeric' required='yes' /&gt; &lt;cfargument name='DSN' type='string' required='yes' /&gt; &lt;cfset var currentClass = '' /&gt; &lt;cfset var addClass = '' /&gt; &lt;cfset var getNewID = '' /&gt; &lt;cfquery name="currentClass" datasource="#Arguments.dsn#"&gt; SELECT class_name, class_description FROM classes WHERE classid = &lt;cfqueryparam value="#Arguments.classid#" cfsqltype="cf_sql_numeric"&gt; &lt;/cfquery&gt; &lt;cfquery name="addClass" datasource="#Arguments.dsn#"&gt; INSERT INTO classes (class_name,class_description) VALUES ('#currentClass.class_name#', '#currentClass.class_description#') &lt;/cfquery&gt; &lt;cfquery name="getNewID" datasource="#Arguments.dsn#"&gt; Select LAST_INSERT_ID() as classid &lt;/cfquery&gt; &lt;cfreturn getNewID.ClassID /&gt; &lt;/cffunction&gt; </code></pre> <p>You should also look into using the result attribute on the cfquery tag as you may be able to replace the last query with it. <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html" rel="nofollow">http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fae.html</a></p> <p>If you are unable to utilize the result method, then I would utilize to ensure that you don't run into race conditions between the two queries.</p> <p>[e] You'll notice I added DSN to the arguments, as you shouldn't reference variables outside the scope of the function! [e2] You should also use cfqueryparam tags in your cfqueries, but I'll let you update that part.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload