> For the complete documentation index, see [llms.txt](https://jks.gitbook.io/khoa-hoc-database-trong-wordpress/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jks.gitbook.io/khoa-hoc-database-trong-wordpress/bai-3-them-sua-xoa-du-lieu-database-wordpress-voi-usdwpdb/cap-nhat-du-lieu-database-wordpress.md).

# Cập nhật dữ liệu database WordPress

Ví dụ ở bảng trên mình muốn sửa số điện thoại của record có id là 1, thì chúng ta sẽ có đoạn code như sau:

Thêm đoạn code sau vào file functions.php của thêm đang sử dụng

```
$data = array(
	    'name' => 'Võ Quang Huy',
	    'email' => 'huykira@gmail.com',
	    'phone' => '0908888888',
	    'title' => 'Hỏi đáp',
	    'content' => 'Mình cần làm website, bạn có thể báo giá cho mình được không!',
	    'date' => current_time( 'mysql' )
	);
	global $wpdb;
	$id = 1;
	$table = $wpdb->prefix . 'contacts';
	$update = $wpdb->update(
        $table,
        $data,
        array('id' => $id)
 );
```

Ở trường hợp sửa dữ liệu thì code cũng tương đồng với code thêm dữ liệu, chỉ có 2 điểm khác so với thêm là:

* Thêm biến **$id** là id của record cần sửa
* **$wpdb->update** thay v&#xEC;**$wpdb->insert**
* Trong hàm thực thi việc sửa dữ liệu chúng ta gán thêm 1 mảng có giá trị là id cần sửa

Kết quả thu về khi chúng ta sửa là:
