Skip to main content
January 20, 2012
Answered

Update is not storing data! PLEASE HELP!

  • January 20, 2012
  • 2 replies
  • 2434 views

This is driving me nuts! I have an update form that does not throw any errors upon submission but does not store data either. I have verified through my cfdump that the data fields are being passed and in the correct data types. I am pretty sure that the problem lies with the primary key. This does not show in my cfdump but I am not sure it should as it is a hidden field. It does show in my source code (which I don't understand since that kind of defeats the purpose of being hidden) so I think it is being passed but I still don not get any update. Please help!

Here is my form:

<form action="update_product.cfm" method="post">

          

<cfoutput query="getProducts">

            <input type="hidden" name"ProductID" value="#ProductID#" />

 

  

   <table>

    <tr>

     <td width="178" style="width: 178px"> </td>

     <td width="375" style="width: 375px"> </td>

     <td width="175" style="width: 105px"> </td>

    </tr>

    <tr>

     <td style="width: 178px">Manufacturer logo:</td>

     <td colspan="2" style="width: 375px"><input name="ManufacturerImage" type="text" style="width: 230px" value="#ManufacturerImage#"></td>

    </tr>

    <tr>

     <td style="width: 178px">Manufacturer:</td>

     <td style="width: 375px"><input name="Manufacturer" type="text" style="width: 230px" value="#Manufacturer#"></td>

     <td style="width: 105px" valign="top"></td>

    </tr>

    <tr>

     <td style="width: 178px">Product title:</td>

     <td style="width: 375px"><input name="ProductTitle" type="text" style="width: 230px" value="#ProductTitle#"></td>

     <td style="width: 105px" valign="top"></td>

    </tr>

    <tr>

     <td style="width: 178px">Product image:</td>

     <td colspan="2" style="width: 375px"><input name="ProductImage" type="text" style="width: 230px" value="#ProductImage#"></td>

    </tr>

    <tr>

     <td style="width: 178px" valign="top">Product description:</td>

     <td colspan="2" rowspan="3" valign="top"><textarea name="ProductDescription" cols="50" rows="10" id="ProductDescription">#ProductDescription#</textarea></td>

    </tr>

    <tr>

     <td style="width: 178px"> </td>

    </tr>

    <tr>

     <td style="width: 178px"> </td>

    </tr>

    <tr>

     <td style="width: 178px" class="auto-style1">Catalog group:</td>

     <td style="width: 375px" class="auto-style1"><select name="CatalogGroup" required="Yes" message="Please select a Catalog Group">

                                 <option selected="selected" value="#CatalogGroup#">#Group#</option></cfoutput>

     <cfoutput query="getGroups">

                                             <option value="#ID#">#Group#</option>

                 </cfoutput>

                    </select></td>

     <td style="width: 105px" class="auto-style1"> </td>

    </tr>

    <tr>

     <td style="width: 178px" class="auto-style1">Species:</td>

     <td style="width: 375px" class="auto-style1"><cfoutput query="getProducts"><select name="Species" >

                                                <option selected="#Species#">#Species#</option>

                                                <option value="Bird & Fowl">Bird & Fowl</option>

                                                <option value="Caged Bird">Caged Bird</option>

                                                <option value="Canine">Canine</option>

                                                <option value="Cattle">Cattle</option>

                                                <option value="Deer">Deer</option>

                                                <option value="Equine">Equine</option>

                                                <option value="Feline">Feline</option>

                                                <option value="Fish">Fish</option>

                                                <option value="Goat">Goat</option>

                                                <option value="Llama & Alpaca">Llama & Alpaca</option>

                                                <option value="Rabbit">Rabbit</option>

                                                <option value="Sheep">Sheep</option>

                                                <option value="Swine">Swine</option>

                                                <option value="Wild Bird">Wild Bird</option>

                                                <option value="Multi/All">Multi/All</option>

                              </select></td>

     <td style="width: 105px" class="auto-style1"> </td>

    </tr>

    <tr>

     <td bgcolor="##FFFFCC" style="width: 178px">Product type</td>

     <td bgcolor="##FFFFCC" style="width: 375px"><select name="ProductType" required="Yes" message="Please select a Product Type">

                                            <option selected="selected" value="#ProductType#">#ProductTypes_ProductType#</option></cfoutput>

     <cfoutput query="getProductType">

                                            <option value="#ID#">#ProductType#</option>

                 </cfoutput>

                    </select></td>

     <td bgcolor="#FFFFCC" style="width: 105px"> </td>

    </tr>

    <tr>

      <td style="width: 178px"> </td>

      <td style="width: 375px"> </td>

      <td style="width: 105px"> </td>

     </tr>

    <tr>

     <td style="width: 178px"> </td>

     <td><input type="submit" value="Update"></td>

     <td style="width: 105px"> </td>

    </tr>

    <tr>

     <td style="width: 178px"> </td>

     <td style="width: 375px"> </td>

     <td style="width: 105px"> </td>

    </tr>

   </table>

  

   

   </form>

Here is my action page:

<cfdump var="#FORM#">

<!--- Update Product data --->
<cfif IsDefined("FORM.ProductID")>

<cfquery datasource="farmky" name="updProducts">
UPDATE Products
WHERE ProductID = #FORM.ProductID#
</cfquery>

</cfif>

<cflocation url="products_master.cfm">

    This topic has been closed for replies.
    Correct answer

    I'm not sure what the point of doing that was?

    In my reply before I was talking about SQL set clauses not ColdFusion <cfset...> tags.  An UPDATE SQL block needs to have SET clauses that tell the database what fields to change to what values with the update.


    Guess what it was.....a friggin' missing equal sign;

    <input type="hidden" name"ProductID" value="27" /> 

    Stare at this stuff long enough and you can't see the obvious cause you're too fixated on finding the bizarre. Thanks for your help ilssac!

    2 replies

    ilssac
    Inspiring
    January 20, 2012

    Your UPDATE query doesn't do anything?

    You have

    UPDATE Products

    WHERE ProductID = keyValue.

    Where are your set statements?

    I.E.  I would expect something like

    UPDATE Products

    SET aField = aValue,

            bField = bValue,

            cField = cValue

    WHERE ProductID = keyValue

    http://www.w3schools.com/sql/sql_update.asp

    There are ways where one does not always have to use the SET key word when working directly in the relational database using other database objects.

    Those do not work with HTML forms AFAIK.

    Can you confrim the the form.productID field has a value in the <cfdump...> clause or not.  Looking at your code, I beleive it should, and if it does not there is another isuuse here besides your UPDATE sql not acutally updating any fields.

    HTH Ian

    January 20, 2012

    No the dump does not show the productid field. What can cause this?

    ilssac
    Inspiring
    January 20, 2012

    I'm not sure, nothing normal or common.

    Question A: 

    You have tripple checked that the HTML the browser is rendering contains the hidden field. 

    I.E. <input type="hidden" name="productID" value="13"/>

    And that this field is between the opening and closing <form...></form> tags.

    Quesiton B:

    And on the update_product.cfm page the <cfdump var="#form#"> does not display a productID field?

    Question C:

    Do you have an Application.cfc and|or Application.cfm in use in this project?  Does it doe anything funny with the form structure in onRequestStart or OnRequest functions?

    If question A and B are true and C is false then something might wierd is going on.

    Have you looked and the Browser request headers to confirm that what should be happening is happening?  If you look at the request header when you submit the form, you should see all the fiields being submitted by the browser that should contains the ProductID field.

    ilssac
    Inspiring
    January 20, 2012

    First off, yes hidden fields will show in the source code.  Yes, they are somewhat mis-named and that many think they are secure because they are hidden.  That is simple not true.  And yes, it should show up in your <cfdump...> and the fact that it does not is an issue.

    Now on to look at your problem.