如何从Wordpress页面更新表格行


How to Update a table row from a Wordpress page

我正试图从Wp数据库中的一个表中更新一行,所有这些都是从wordpress中的一页中更新的。我正在使用一个插件,它允许我在页面内编写php,我正在编写以下内容:

$ident = $_GET['id'];
echo $ident;
global $wpdb;
$table_name = $wpdb->prefix . ' wp_cf7dbplugin_submits';
$data = array(
 'field_name' => 'p'
);
$where = array( 'submit_time' => $ident );
$format = array( '%s', '%d' );
$where_format = array( '%d' );
$wpdb->update( $table_name, $data, $where, $format, $where_format );

非常感谢你的帮助。

$wpdb->prefix是您的数据库前缀。默认情况下,这是"wp_"。

这意味着在您的代码中有以下行:

$table_name = $wpdb->prefix . ' wp_cf7dbplugin_submits';

相当于:

$table_name = 'wp_ wp_cf7dbplugin_submits';

您需要删除重复的前缀和文本前面的空格。

$table_name = $wpdb->prefix . 'cf7dbplugin_submits';

我还将研究另一种添加代码的解决方案。在编辑器中使用允许PHP的插件是个坏主意。