PHP select query not getting updated records
<p>I am working on a php form using POST and use dynamic HTML tables. I truncate the DB table every time before inserting the data in to the table which seems fine.</p>

<p><strong>Select query when the page loads (to update UI part)</strong></p>

<pre><code>$query = 'SELECT * FROM TABLENAME';
$result = mysqli_query($dbConnection, $query);
$rows = array();
if(!$result)
{
    //log error
}
if ($result-&gt;num_rows &gt; 0) 
{
    while($row = $result-&gt;fetch_assoc()) 
    {
        print_r( $row);
        $rows[] = $row;
    }
}
</code></pre>

<p><strong>Insert part</strong></p>

<pre><code>if(isset($_POST['u']))
{
    foreach($_POST['u'] as $key =&gt; $value)
    {
        $ky = $_POST['x'][$key];

        $query = "INSERT INTO TABLENAME (ID,KY) VALUES ($value, '$ky')";
        $result = mysqli_query($dbConnection, $query);
    }
}
</code></pre>

<p>However, upon posting, when using select query, it seems to not get the latest records inserted, I made sure to check the records are inserted properly in PhpMyadmin.</p>

<p>When I reload the page, it works fine. Only thing is it's not getting the updated records when it's POSTed, but works the subsequent times. </p>

<p>I thought it could be due to connection object and tried to use different connections objects with no luck.</p>

<p>INFO: Not sure if it has any impact, the database is a wordpress and I created new table in this database for this.</p>

<p>Thanks in advance...</p>