[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Entering data from an array into a database using ColdFusioin

Asked by lonnyo in Cold Fusion Markup Language, WebApplications

I am trying to enter data from an array into a database and keep getting an error.

My array is generated from a form and then converted to a Session structure because I will be adding it in the database later.  Here is the code for this:

<cfset Sleeps = 6> <!---Temporary value set - This will come from a database--->
<cfform name="formGuests" id="formGuests" method="post">
    <h3>Please enter the names, ages and relationship to person booking the property. If less than guests, leave the additional spaces blank.</h3>
    <table class="guests">
        <tr><td width="255">Guest(s)</td><td width="55">Age</td><td width="155">Relationship</td></tr>
    </table>
    <cfloop from="1" to="#Sleeps#" index="i">
    <label for="Guest#i#">
    <cfif i EQ 1>
        <cfinput type="text" name="Guest#i#" size="35">
        <cfinput type="text" name="Age#i#" size="3">
        <cfinput type="hidden" name="Relationship#i#" value="Remitter">
    <cfelse>
        <cfinput type="text" name="Guest#i#" size="35">
        <cfinput type="text" name="Age#i#" size="3">
        <cfinput type="text" name="Relationship#i#">
    </cfif>
    </label><br />
    </cfloop>
    <br />
    <cfinput type="hidden" name="maxOccupancy" value="6">
    <cfinput type="submit" name="SubmitForBooking" id="SubmitForBooking" value="Continue" />
</cfform>


<cfif IsDefined("SubmitForBooking")>
      <cfset arrayGuest = []>
   
    <!--- for each line in the form, extract the values and add it to your array --->
    <cfloop from="1" to="#form.maxOccupancy#" index="i">

            <!--- create a new structure to store the new line of information --->
        <cfset guestInfo = {} >
       
        <!--- store the values of each form field --->
        <cfset guestInfo.guest = FORM["Guest#i#"]>
        <cfset guestInfo.age = FORM["Age#i#"]>
        <cfset guestInfo.relationship = FORM["Relationship#i#"]>
       
        <!--- add the new guest to your array --->
        <cfset arrayAppend(arrayGuest, guestInfo)>
    </cfloop>

      <!---Create the Session struction for the Guests array--->
    <cflock timeout="20" scope="session" type="exclusive">
        <cfset SESSION.Guests = StructNew()>
    </cflock>
   
    <!---- Dump the data to see the results --->
    <cfset Session.Guests.arrayGuest = arrayGuest>
    <cfdump var="#Session.Guests#">
</cfif>

Here is the code I am using to enter into the database:

<cfset OrderID = 1> <!---Temporary value set - This will come from a database--->
<cfloop from="1" to="6" index="i">
      <cftransaction>
        <cfquery datasource="#DataSource#" name="insertGuests">
            INSERT INTO guests
                    (OrderID, GuestName, GuestAge, Relationship)
            VALUES       (<cfqueryparam value="#Trim(OrderID)#" cfsqltype="cf_sql_integer">,
                     <cfqueryparam value="#Trim(Session.Guests.arrayGuest.Guest[i])#" cfsqltype="cf_sql_varchar">,
                     <cfqueryparam value="#Trim(Session.Guests.arrayGuest.Age[i])#" cfsqltype="cf_sql_integer">,
                               <cfqueryparam value="#Trim(Session.Guests.arrayGuest.Relationship[i])#" cfsqltype="cf_sql_varchar">)
        </cfquery>
    </cftransaction>
</cfloop>

The error I am getting is:

Element GUESTS.ARRAYGUEST.GUEST is undefined in a Java object of type class [Ljava.lang.String; referenced as ''
[+][-]11/03/09 05:16 AM, ID: 25728574Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Cold Fusion Markup Language, WebApplications
Sign Up Now!
Solution Provided By: azadisaryev
Participating Experts: 2
Solution Grade: A
 
[+][-]11/03/09 05:44 AM, ID: 25728810Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625