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
and here I'm trying to update it
<?php
$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->update(
$wpdb->prefix . 'tropix_dmin',
$data
);
?>
<table class="widefat" style="border-radius:4px;">
<tr>
<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>
</tr>
<?php foreach ( $post_name1_results as $post_names ) {
$this_data = unserialize($post_names->post_name1);
//echo "<pre>";
//print_r($this_data);
if($this_data != ""){
?> <form action="" method="POST">
<div class="form">
<input type="submit" value="SUBMIT">
</div>
<!--col2 ends here-->
</section>
<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>
</tr>
<?php }
} ?>
</table>
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
and here I'm trying to update it
<?php
$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->update(
$wpdb->prefix . 'tropix_dmin',
$data
);
?>
<table class="widefat" style="border-radius:4px;">
<tr>
<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>
</tr>
<?php foreach ( $post_name1_results as $post_names ) {
$this_data = unserialize($post_names->post_name1);
//echo "<pre>";
//print_r($this_data);
if($this_data != ""){
?> <form action="" method="POST">
<div class="form">
<input type="submit" value="SUBMIT">
</div>
<!--col2 ends here-->
</section>
<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>
</tr>
<?php }
} ?>
</table>
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->update(
$wpdb->prefix . 'tropix_dmin',
array( 'post_name1' => $arr),
array( 'id' => $id ),
array( '%s' ),
array( '%d' )
);