Insert Loop values into DB Problem

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Insert Loop values into DB Problem

    :confused;

    How do I call the loop when inserting the values into my DB? I am getting an
    error message.

    Here is the Insert Statement:


    Insert into Scenario
    (ScenarioID, Scenario_Desc, Scenario, TeamOwner, TeamOwnerSub,
    ProcessOwner, ScriptOwner, Status)
    Values
    ('#Session.ScenarioID#',
    '#Trim(Form.Scenario_Desc)#',
    '#Trim(Form.Scenario)#',
    '#trim(form['myTeam' & myLoop])#',
    '#trim(form['mysubTeam' & myLoop])#',
    '#Trim(Form.Process)#',
    '#Trim(Form.Script)#',
    '#Trim(Form.Status)#',)


    Error Message:
    Variable MYLOOP is undefined.


    The error occurred in
    D:\Inetpub\wwwroot\Projects\TestScenario\_actions\ act_CreateScenario.cfm: line
    10

    8 : '#Trim(Form.Scenario_Desc)#',
    9 : '#Trim(Form.Scenario)#',
    10 : '#trim(form['myTeam' & myLoop])#',
    11 : '#trim(form['mysubTeam' & myLoop])#',
    12 : '#Trim(Form.Process)#',


    DJ5MD Guest

  2. Similar Questions and Discussions

    1. #39464 [NEW]: Range function produces odd values in foreach loop
      From: netnessie at gmail dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: *Programming Data Structures Bug...
    2. What's faster - loop for insert or insert...select.
      What is faster if I'm moving large numbers of records (anywhere from 10,000 to 300,000 records per archive) from one query to another table? 1)...
    3. Can you put an Insert Command object in a loop?
      Hi I am trying to figure out how to insert a variable number of records into one table in Access, therefore without stored procedures, in ASP...
    4. insert record loop
      Can anyone help me to create an insert record loop using asp vbs?
    5. How to select and then loop while insert
      I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and...
  3. #2

    Default Re: Insert Loop values into DB Problem

    What is 'myLoop' supposed to represent? The index of the loop? What does the entire code for the loop look like?



    BSterner Guest

  4. #3

    Default Re: Insert Loop values into DB Problem

    Here is the JS code:

    <script language="javascript">
    var aryTeams = new Array();

    <cfset variables.JSLoop = 0 />
    <cfoutput>
    <cfloop query="qrygetteams">
    aryTeams[#variables.JSLoop#] = new
    Array("#qrygetteams.IssueTeamTitle#", "#qrygetteams.IssueSubTeamTitle#");
    <cfset variables.JSLoop = variables.JSLoop + 1 />
    </cfloop>
    </cfoutput>

    <!--- Function that will update the Selects --->
    function tsrUpdSelects(frstSel, scndSel, thisSel) {
    var z;
    var chkTeam = "";

    if(thisSel.name == frstSel.name) {
    scndSel.options.length = 0;
    scndSel.options[scndSel.length] = new Option("Select SubTeam",
    "");

    if(thisSel.options[thisSel.selectedIndex].value != "") {
    for (z = 0; z < aryTeams.length; z++) {
    if(aryTeams[z][0] ==
    thisSel.options[thisSel.selectedIndex].value &&
    chkTeam.lastIndexOf(aryTeams[z][1] == -1)) {
    scndSel.options[scndSel.length] = new Option
    (aryTeams[z][1], aryTeams[z][1]);
    chkTeam = chkTeam + aryTeams[z][1];
    }
    }
    }
    }
    }
    </script>

    Here is the Select Box code:

    <cfloop from="1" to="1" index="Variables.myLoop">
    <tr>
    <td height="30">Team Ownership: </td>
    <cfset TeamList = ""/>
    <td><select name="myTeam#myLoop#"
    onChange="tsrUpdSelects(this,this.form.mySubTeam#M yLoop#, this);">
    <option value="" selected> Select Project Team</option>
    <cfloop query="qrygetteams">
    <cfif not listFindNoCase(TeamList, qrygetteams.IssueTeamTitle,",")>
    <option
    value="#qrygetteams.IssueTeamTitle#">#qrygetteams. IssueTeamTitle#</option>
    <cfset TeamList = listAppend(TeamList,qrygetteams.IssueTeamTitle,"," ) />
    </cfif>
    </cfloop>
    </select>
    <img src="../../_images/spacer.gif" width="25" height="10">
    <select name="mySubTeam#myLoop#"
    onChange="tsrUpdSelects(CreateScenario.myTeam#myLo op#, this);">
    <option value="" selected> Select Project SubTeam</option>
    </select>
    </td>
    </tr>
    </cfloop>
    </cfoutput>

    DJ5MD Guest

  5. #4

    Default Re: Insert Loop values into DB Problem

    Variables in the "variables" scope don't persist across page requests. The
    page you're posting to, that's trying to access...

    '#trim(form['myTeam' & myLoop])#',
    '#trim(form['mysubTeam' & myLoop])#',

    Knows about the 'form' variables', but not the 'myLoop' variable that was set
    in the previous page. This is the case even if the page is posting to itself.

    Couple questions.

    1) Why do you have a loop that loops from '1' to '1'?
    2) Consider using the 'selectedIndex' property of your select boxes to set
    values, rather than looping through all that stuff.

    (Assuing you have a form with <form name="myForm"....>

    function updateSubTeam() {
    var theForm = document.myForm;
    var myTeam1Index = theForm.myTeam1.options.selectedIndex;
    var selectVal = aryTeams[myTeam1Index-1][1];

    theForm.mySubTeam1.options[0] = new Option("Select SubTeam", "");
    theForm.mySubTeam1.options[1] = new Option (selectVal, selectVal);
    }


    BSterner Guest

  6. #5

    Default Re: Insert Loop values into DB Problem

    I was modifying a JS script and CF that allowed for Multiple Related Select
    boxes. I had no idea how to do that, so I found this code and modified to my
    needs so I have no idea why the cfloop is 1 to 1. I do know that when I
    change the cfloop to 1 to 5 then the form elements show up 5 times on the page
    (repeat).

    If I use this code then will I still be able to have the Multiple related
    select boxes?

    DJ5MD Guest

  7. #6

    Default Re: Insert Loop values into DB Problem

    Ok, well get rid of the <cfloop> tags then. The purpose of a loop is to
    um...."loop", and it sounds like you don't need that. Just hard-code the '1'
    and the '2' in your select box names.

    "If I use this code then will I still be able to have the Multiple related
    select boxes?"

    Yes, it should. Wouldn't hurt to test it in multiple browsers, though. Just
    make sure all the element names match up.


    BSterner Guest

  8. #7

    Default Re: Insert Loop values into DB Problem

    :)

    So where it says myTeam#myLoop# for MyTeam I would use myTeam[1] and when
    referencing mySubTeam#myLoop# I would use mysubTeam[2]?

    Also, what code am I replacing with the code you suggested and where do I
    place it?

    DJ5MD Guest

  9. #8

    Default Re: Insert Loop values into DB Problem

    Names would be "myTeam1" & "mySubTeam1".
    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139