How To Update row in custom wordpress table How To Update row in custom wordpress table wordpress wordpress

How To Update row in custom wordpress table


Try this code

A simple WordPress Update query

WP Update

$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);

Hope this will help you


Try this code.

$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)    );


$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!';}