Why last row deleted when refresh page

Question

when I refresh page table row deleted and last query deleted when I click on any delete button of other row. Why is this happened?

this is table which I displayed

                <?php
                global $wpdb;
                $table= 'wp_contact_form';
                $result = $wpdb->get_results ( "SELECT * FROM $table" );

                if(!empty($result)){

                foreach ( $result as $print ) {  
                        
                ?>
                <tr>
                <td><?php echo $print->id;?></td>
                <td><?php echo $print->names;?></td>
                <td><?php echo $print->emails;?></td>
                <td><?php echo $print->gender;?></td>
                <td><?php echo $print->age;?></td>
                <td><input type="submit" value="Edit" id="" name="update"></td>
                <td><input type="submit" value="delete" id="delete" name="delete"></td>
                </tr>
                <?php
                }
                } 
                ?>

this is delete query

                   $id= $print->id;
                   if(isset($_POST['delete']))
                    {
                      $result = $wpdb->delete($table, array('id' => $id));
                    if(!empty($result))
                       {
                        echo "success";
                       }
                    }
0
Vishal 2 weeks 0 Answers 2 views 0

Leave an answer