| Workflow  Step 1: tạo file Các bước thực hiện câu lệnh MySQL trong PHP như sau:vidu_insert.php
 	Tạo kết nối đến database mong muốn (nhúng file dbconnect.phpvào file đang viết code)Chuẩn bị câu lệnh (QUERY) mong muốn:
 	Thường sử dụng tên biến $sqlYêu cầu PHP thực  thi câu lệnh trên bằng hàm mysqli_query($conn, $sql) <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Ví dụ INSERT dữ liệu</title>
</head>
<body>
    <?php
    // Truy vấn database để lấy danh sách
    // 1. Include file cấu hình kết nối đến database, khởi tạo kết nối $conn
    // Ví dụ: file đang viết code ở /example/thuc_thi_cau_lenh_insert.php
    // C:\xampp\htdocs\web02\dbconnect.php vào file đang viết code
    // 
    include_once(__DIR__ . '/../dbconnect.php');
    // 2. Chuẩn bị QUERY
    $tenhinhthucthanhtoan = 'Thanh toán SHIPCOD (giao hàng mới trả tiền)'; //$_POST['httt_ten'];
    $sql = "INSERT INTO `hinhthucthanhtoan`(httt_ten) VALUES('$tenhinhthucthanhtoan');";
    // 3. Thực thi
    mysqli_query($conn, $sql);
    ?>
</body>
</html> |