我正在开发一个插件,现在我想更新我的表记录....我正在使用此代码从数据库中获取数据
<?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);
?>
<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 != ""){
?>
<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>
但我需要更新数据......我也发送了数据库的截图....请帮帮我
[1]: https://i.stack.imgur.com/4kset.jpg
答案 0 :(得分:-1)
如果要更新列,则查询应为:
$query = "UPDATE (*table*) SET (*column to update*) = '*value*' WHERE id= $id";
要回显现有列,请使用:
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$query = mysqli_query($this->db_connection,"SELECT *column* FROM *table* WHERE id='*your id*'");
$value = mysqli_fetch_all($query,MYSQLI_ASSOC);
echo $value[0]['column name'];
尽管注意SQL注入。