Getting old data from mysql database when appending to div
<p>I have a main page on which I have a button which opens a popup. When closing this popup then I have a script which calls to a php file to select data from the database. This selected data will be appended to a div in the main page:</p>

<pre><code> if (win.closed !== false) { 
    window.clearInterval(pollTimer);
    $.get("&lt;?php echo $GLOBALFILESPHPFORJS ?&gt;DBtoOCI.php", { ReferenceKey: Reference  } )
    .done(function( data ) { 
      console.log( data );
      $("#ItemData").append(data);
     });
</code></pre>

<p>The first time it nicely selects and appends the data. If I for example have a column called <code>animalname</code> which has 1 row with the data "Cat" then in my div I see cat. If I then delete the row uit of my database and add a row with a row called "Tiger" and then open and close the popup again, then get new data added to the div so it becomes: "Cat Tiger", But it is becomes "Cat Cat"! Why is this so?</p>

<p>Selecting data from database:</p>

<pre><code>$sqlReturnExistingOCI = "SELECT * FROM animal WHERE animalname= ?";


      if($stmt = $conn-&gt;prepare($sqlReturnExistingOCI)) 
        {    
            mysqli_stmt_bind_param($stmt, "s", $referencekey);

            if(!$stmt-&gt;execute()) 
            { 
                echo $stmt-&gt;error;
            } 
            else 
            { 

              $result = mysqli_stmt_get_result($stmt);
              while ($row = mysqli_fetch_array($result)) {

                 echo $row['animalname'];
               }
              $stmt-&gt;free_result(); 
              $stmt-&gt;close; 
            }
        }
</code></pre>