How to update form data inserted in database in wordpress?
update form data inserted in database in wordpress
if(isset($_POST['contactformupdate'])) { $id = $_REQUEST['id']; extract($_POST); global $wpdb; $table_name = $wpdb->prefix . "my_plugintable"; if(($wpdb->update($table_name, array('firstname'=>$firstname, 'lastname'=>$lastname, 'email'=>$email, 'phone'=>$phone, 'message'=>$message), array('ID'=>$id)))){ $msg = "Your message has been sent!"; } else { $msg = "Something is wrong!"; } } get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main"> <?php $id = $_REQUEST['id']; global $wpdb; $table_name = $wpdb->prefix . "my_plugintable"; $result = $wpdb->get_results ( "SELECT * FROM $table_name where ID=$id" ); foreach ( $result as $print ) { ?> <form id="contact-form" method="post" action=""> <h2>Update Details</h2> <div class="row two-col"> <div class="first-col"> <label>First Name</label> <input type="text" name="firstname" class="contact-firstname" value="<?php echo $print->firstname;?>"> <i class="first-i"></i> </div> <div class="second-col"> <label>Last Name</label> <input type="text" name="lastname" class="contact-lastname" value="<?php echo $print->lastname;?>"> <i class="last-i"></i> </div> </div> <div class="row two-col"> <div class="first-col"> <label>Email</label> <input type="text" name="email" class="contact-email" value="<?php echo $print->email;?>"> </div> <div class="second-col"> <label>Phone</label> <input type="text" name="phone" class="contact-phone" value="<?php echo $print->phone;?>"> </div> </div> <div class="row one-col"> <div class="single-col"> <label>Message</label> <textarea name="message" class="contact-message"> <?php echo $print->message;?></textarea> </div> </div> <div class="row one-col"> <div class="single-col"> <input type="submit" value="Update" name="contactformupdate" class="contact-submit"> <?php echo $msg; ?> </div> </div> </form> <?php } ?> </main><!-- #main --> </div><!-- #primary -->
POST COMMENTS