Ive尝试并尝试查找如何在自定义Wordpress表中进行编辑/更新行我将其设置为获取当前登录用户的用户名,然后将其与自定义wp_表进行比较,其中UserNAme为主键然后我想通过在确认当前登录用户匹配之后通过传递变量的值来编辑该特定行上的特定列/字段在我的自定义表中的主键用户名" wp_customers"我用这行代码做错了什么或者你有更好的解决方案
$current_user = wp_get_current_user();
$johnny = $current_user->user_login;
$subs = 'illinois';
global $wpdb;
$wpdb->query(
"
UPDATE $wpdb->wp_Customers
SET BuyersAddress = $subs
WHERE UserName = $johnny
");
答案 0 :(得分:5)
试试此代码
一个简单的WordPress更新查询
$current_user = wp_get_current_user();
$johnny = array('UserName' => $current_user->user_login);
$subs = array('BuyersAddress' => 'illinois');
global $wpdb;
$table_name = $wpdb->prefix."Customers";
$wpdb->update($table_name, $subs, $johnny);
希望这会对你有所帮助
答案 1 :(得分:4)
试试这段代码。
$current_user = wp_get_current_user();
$johnny = $current_user->user_login;
$subs = 'illinois';
global $wpdb;
$table_name = $wpdb->prefix."Customers";
$wpdb->query( $wpdb->prepare("UPDATE $table_name
SET BuyersAddress = %s
WHERE UserName = %s",$subs, $johnny)
);
答案 2 :(得分:0)
$msg='';
if(isset($_POST['submit']) && $_POST['submit']=='Submit')
{
$assID =12; //pass your table id
$table_name = $wpdb->prefix."assigned_user"; //custom table name
$ds = $_POST['driverStatus'];
$wpdb->query( $wpdb->prepare("UPDATE $table_name SET driverStatus = '".$ds."' WHERE id ='".$assID."' ")
);
$msg = 'Successfully Delivered!';
}