Move insert
query to top of file. So it will select updated data.
<?php
// Save form data
if(isset($_POST['submit'])){
global $wpdb;
$votes = 1;
$competition = $_POST['comp'];
$uid = $_POST['id'];
//$uid = get_current_user_id();
echo 'id of image=".$_POST["id'];
echo '<br>'.'competition is'.$_POST['comp'];
if($wpdb->insert(
'votes',
array(
'votes' => $votes,
'competition' => $competition,
'uid' => $uid
)
) == false) wp_die('Database Insertion failed'); else echo 'Database insertion successful<p />';
}
// Get already updated results
$results = $wpdb->get_results($sql) or die(mysql_error());
foreach( $results as $result ) {
echo '<form action="" method="post">';
echo "<img src="https://wordpress.stackexchange.com/questions/183684/$result->path" width="150" height="150" >" . '<br><br>';
echo "<input name="id" type="hidden" value="$result->uid">";
echo "<input name="comp" type="hidden" value="$result->competition">";
echo $result->username.'<br>';
echo $result->votessum.'<br>';
echo "<input style="margin-bottom:30px;" value="vote" name="submit" type="submit"/></form>";
}
?>