Title: update page after insert query
Last modified: August 24, 2016

---

# update page after insert query

 *  [pluspt2001](https://wordpress.org/support/users/pluspt2001/)
 * (@pluspt2001)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/update-page-after-insert-query/)
 * I am working in wordpress. You will see two queries one is select and the other
   is insert query. I want that after my insert query is run i get updated results
   on my page.
 * The select query has a form tag with submit button … which when submitted picks
   the id or current fetched row and performs an insert at the same id in another
   table. But after this click on submit my page does not show the updated value
   or inserted value from database. I hope you people can advise in this … thanks.
 * PHP code in wordpress page template
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       $sql = "SELECT 1user.uid, 1user.username, 1user.competition, 1user.path, Sum(votes.votes) AS votessum FROM 1user LEFT JOIN votes on 1user.uid=votes.uid GROUP BY 1user.username, 1user.competition";
   
       $results = $wpdb->get_results($sql) or die(mysql_error());
   
       foreach( $results as $result ) {
       echo '<form action="" method="post">';
       echo "<img src='$result->path' width='150' height='150' >" . '
   
       ';
       echo "<input name='id' type='hidden' value='$result->uid'>";
       echo "<input name='comp' type='hidden' value='$result->competition'>";
       echo $result->username.'';
   
       echo $result->votessum.'';
       echo "<input style='margin-bottom:30px;' value='vote' name='submit' type='submit'/></form>";    
   
       }
   
       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 ''.'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 />';
       ```
   

The topic ‘update page after insert query’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [pluspt2001](https://wordpress.org/support/users/pluspt2001/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/update-page-after-insert-query/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
