why update and delete query not worked in custom table?

Question

this is custom template. I wrote crud by using wordpress query to sent data in custom table of database and get from database, insert query worked, but update and delete query not working. Below I give update and delete query, please suggest if anyone knows?

     <?php
     /* 
      * Template Name: Show Form Template Page
      */
     ?>
    <div class="container">
       <div class="row">
        <div class="col-md-12">
            <table border="1">
                <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Email</th>
                <th>Gender</th>
                <th>Age</th>
                <th>Edit</th>
                <th>Delete</th>
                </tr> 


                <?php

                global $wpdb;
                $table = '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><button class="">Edit</button></td>
                <td><button name="delete">Delete</button></td>
                </tr>
                <?php
                }
                }  
                ?>
        </table>
                <?php
                $id= $result->id;
                global $wpdb;
                $table='contact form';
                if (isset($_POST['update'])) {
                    $data=array(
                            'names' => $_POST['yourname'],
                            'emails'    => $_POST['customer_email'],
                            'gender' => $_POST['customer_gender'],
                            'age' => $_POST['customer_age']
                                );
                    $wherecondition=array(
                                    'id'=>$id
                                );
                $updated=$wpdb->update($table, $data, $wherecondition);
            }
                
                if (isset($_POST['delete'])) {

                    $deletedrow= $wpdb->delete($table, $wherecondition);
                    }
                    ?>

        </div>
     </div>
    </div>

0
Vishal 1 month 0 Answers 6 views 0

Leave an answer