Refresh Page when Comment is Added

Currently anytime I add a comment. It adds the comment to the database but freezes the buttons that I have so they do not work. Although if I refresh the page they work again. Is there a way to get the page to refresh after a comment is added. Currently the following is the code that I have.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>
            Untitled Document
        </title>

        <cfquery datasource="AccessTest" name="qTest">
            SELECT P.Account, P.Image, P.Image_ID, C.Remarks, C.Users, C.Accounts, C.Date_Time
            FROM PictureDB AS P
            INNER JOIN CommentsDB AS C
            ON C.Image_ID = P.Image_ID
            ORDER BY P.Image_ID
        </cfquery>

        <script src="http://code.jquery.com/jquery-2.0.3.js">

        </script>

        <script>
            $(document).ready(function(){
                  var images = {
                    <cfoutput query="qTest" group="Image_ID">
                        "#qTest.Image_ID#": {
                            "image": "#qTest.Image#",
                            "remarks": [
                            <cfoutput>
                                "#qTest.Users#, #qTest.Date_Time# <br> #qTest.Remarks# <br> </br>",
                            </cfoutput>
                            ]
                        },
                    </cfoutput>
                };
                  $("button").click(function(event){
                    event.preventDefault();
                    var id = $(this).data("id");
                    var src = images[id].image;
                    var desc = images[id].remarks.toString();

                    $("#theImage").attr("src", src).removeClass("hide");
                    $("#theDescription").html(desc).removeClass("hide");
                    });
                });
        </script>
    </head>

    <body>


        <cflayout name="myAccordionLayout" type="accordion" width="600px">

            <cflayoutarea title="Bill Analysis" align="left">
                        <cfoutput query="qTest" group="Account">
                    <button data-id="#qTest.Image_ID#">
                        #qTest.Account#

                    </button>

                </cfoutput> 

                    <cfform name="InsertComments" id="InsertComments">
            <fieldset>
<div id="container">
    <div id="mainContent">


            <textarea name="Remarks" cols="55" rows="4" label="Tour Description"
                                    required="yes" validateat="OnSubmit" message="Please enter your comment here" 
                                    enabled="no">
                        </textarea>
            <input type="text" name="Image_ID" message="Please enter Account Here." 
                                 validateat="onSubmit" required="yes" id="Image_ID" size="10"
                                 maxlength="60">
                        </input>
        <input type="submit" name="insertComments" value="Insert Comments" id="submit">
                        </input>
        </div>
    </div>  
    </fieldset>
    </cfform>
        <cfif IsDefined("form.InsertComments")>

                    <cfquery datasource="AccessTest">
                        INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
                        VALUES
                        (<cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">

                        , <cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">

                        , <cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">

                        )
                    </cfquery>

            </cfif>


                <img id="theImage" class="hide">
        <div id="theDescription" class="hide">
        </div>
            </cflayoutarea>
            <cflayoutarea title="Operations Analysis">
        Test
            </cflayoutarea>
        </cflayout>
        </body>
</html> 

Answers


Haven't you posted this code before?

Why not just do a <cflocation> after you execute your query back to the page? This way a user wont refresh and re submit the form and it also solves your refreshing problem.

<cfif IsDefined("form.InsertComments")>
      <cfquery datasource="AccessTest">
            INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
            VALUES
                 (
                    <cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">
                    ,<cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">
                    ,<cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">
                 )
      </cfquery>
      <cflocation url="URL OF PAGE" addToken="false" />
</cfif>

Need Your Help

Correctly encode characters in a PHP mail form ("I'm" turns to be "I\'m")

php email encode

I'm testing a PHP mail form, a very barebones one, found here:

PHP MySQLi Query Not Working

php mysql mysqli

I am attempting to insert data into my users table in my database whenever a user signs up, however, I am having trouble doing so..