I am developing a plugin now i want to update my table record.... I'm using this code to fetch data from database

But i need to update data... also i am sending the screenshot of the database.... please help me enter image description here

and here I'm trying to update it

$id = $_GET['id'];
$dirname = dirname(__FILE__);
$root = false !== mb_strpos( $dirname, 'wp-content' ) ? mb_substr( $dirname, 0, mb_strpos( $dirname, 'wp-content' ) ) : $dirname;
require_once( $root . "wp-load.php" );

    global $wpdb;
     $post_name_table = $wpdb->prefix . "tropix_dmin";
     $query = "
        SELECT post_name1, id
        FROM $post_name_table
        WHERE id= $id";
    $post_name1_results = $wpdb->get_results($query); 

    $arr = serialize($_POST);

    global $wpdb;
        $data = array( 
            'post_name1'    => $arr,

            $wpdb->prefix . 'tropix_dmin',


    <table class="widefat" style="border-radius:4px;">

    <th class="manage-column" scope="col" style="font-weight:bold; font-size:20px;">Field</th>
    <th class="manage-column" scope="col" style="font-weight:bold; font-size:20px;">Value</th>
  <?php foreach ( $post_name1_results as $post_names ) {

    $this_data = unserialize($post_names->post_name1);
    //echo "<pre>";

    if($this_data != ""){

   ?>    <form action="" method="POST">
    <div class="form">
    <input type="submit" value="SUBMIT">
  <!--col2 ends here-->

  <tr class="alternate iedit">
    <td class="column-columnname">Street Address</td>
    <td class="column-columnname"><input type="text" value="<?php echo $this_data['Street_Address']; ?>" /></td>
 <?php }
  } ?>
  • but where are you trying to update it? I can't see any code to submit the data Nov 16, 2017 at 12:09
  • Thank you, Piyush for the reply..... please check the code again after the image
    – ali arslan
    Nov 16, 2017 at 12:23

1 Answer 1


It's really hard to understand what are you actually doing ( a refactor will help also).

but for updating you can try: You will need the $id, show you tell which row to update.

    $wpdb->prefix . 'tropix_dmin',
    array( 'post_name1' => $arr),
    array( 'id' => $id ),
    array( '%s' ),
    array( '%d' )
  • Drupalizeme thankx for the answer i am just fetching data from database and showing it into the input box and then trying to update it..... with your code when i update it just sending an empty field data
    – ali arslan
    Nov 16, 2017 at 13:15
  • and all other data is now automatically deleting when i update it with your code
    – ali arslan
    Nov 16, 2017 at 13:17
  • 1
    This is an example you should make it work with your code. For example, updating you should have the required $id and also the valid $arr data to work. If for some reason the $arr is empty it should add an empty value. This mean you should check first if(!empty($arr)) {..} so you have some data before trying to update. Nov 16, 2017 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.