Cách lưu trữ dữ liệu biểu mẫu html

Thu thập dữ liệu biểu mẫu khách hàng là một nhiệm vụ phổ biến trong phát triển web. Biểu mẫu liên hệ làm cho trang web của bạn chuyên nghiệp hơn và gửi tín hiệu rõ ràng rằng bạn quan tâm đến việc kinh doanh với khách hàng tiềm năng của mình. Việc thiếu một trong những có thể làm cho doanh nghiệp của bạn có vẻ lỗi thời hoặc không chuyên nghiệp. Mọi người có nhiều khả năng ủng hộ sản phẩm của bạn hơn nếu bạn có khả năng tiếp cận cao. Đây là một cách tuyệt vời để tăng khả năng hiển thị của doanh nghiệp bạn

Các lý do khác để triển khai biểu mẫu liên hệ

  1. Nó làm cho trang web của bạn chuyên nghiệp hơn
  2. Bảo vệ
  3. Làm cho bản thân dễ tiếp cận hơn
  4. Tự động trả lời email

Hôm nay, chúng ta sẽ học cách chèn dữ liệu biểu mẫu khách hàng vào cơ sở dữ liệu MySQL bằng HTML và PHP. Chúng tôi sẽ tạo một biểu mẫu HTML và tập lệnh PHP để chèn dữ liệu vào cơ sở dữ liệu bằng cách sử dụng



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
2

điều kiện tiên quyết

  • Máy chủ XAMPP
  • PHP
  • HTML
  • mysql

Hướng dẫn

Ví dụ, điều đầu tiên chúng ta cần làm là tạo biểu mẫu



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
3. Biểu mẫu HTML là tài liệu lưu trữ thông tin về tương tác của người dùng với trang web. Biểu mẫu là cách để người dùng gửi thông tin đến cơ sở dữ liệu

 action="/action_page.php" method="POST">
  Form Elements...
 

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Thuộc tính



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
4 cho biểu mẫu biết nơi gửi dữ liệu. Thuộc tính


// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
5 cho biểu mẫu biết cách gửi dữ liệu

Kết nối với cơ sở dữ liệu

Cơ sở dữ liệu là một tập hợp dữ liệu. Đó là một cách để lưu trữ và truy xuất dữ liệu từ máy tính hoặc máy chủ

Xampp là viết tắt của "Nền tảng MySQL mở rộng của Apache". Đây là một phần mềm mã nguồn mở và miễn phí cho phép bạn chạy một máy chủ cơ sở dữ liệu trên máy tính của mình. Nó sử dụng MySQL, Apache, PHP và Perl làm công cụ cơ sở dữ liệu và nó miễn phí sử dụng

Mã PHP ví dụ



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Xử lý dữ liệu biểu mẫu

Chúng tôi có thể thu thập dữ liệu biểu mẫu được gửi qua biểu mẫu HTML mà chúng tôi sẽ tạo. Chúng ta có thể sử dụng biến



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
6 để thu thập dữ liệu



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Thiết lập máy chủ Xampp của bạn

Để kết nối thành công với cơ sở dữ liệu và gửi dữ liệu biểu mẫu của chúng tôi, chúng tôi cần thiết lập máy chủ Xampp của mình để chấp nhận dữ liệu đến

  • Trước tiên, chúng ta cần khởi động máy chủ Xampp của mình
  • Điều hướng đến
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    0
  • Tạo tên cơ sở dữ liệu của
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    1 và tên bảng của
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    2
  • Tạo các tệp HTML và PHP của chúng tôi trong Trình chỉnh sửa mã của chúng tôi. Tôi đang sử dụng Visual Studio Code
  • Gửi dữ liệu của chúng tôi thông qua biểu mẫu chúng tôi đã tạo
  • Kiểm tra kết quả và xác minh rằng tất cả dữ liệu đã được chèn thành công

Quá trình

Trước tiên, bạn sẽ muốn đảm bảo rằng bạn đã cài đặt XAMPP Server trên máy cục bộ của mình. Sau khi được cài đặt, trước tiên hãy bắt đầu bằng cách mở ứng dụng Xampp của chúng tôi. Trong trường hợp của tôi, tôi đang sử dụng Macbook Pro nên mọi thứ có thể hơi khác một chút nếu bạn đang sử dụng Windows hoặc hệ điều hành khác. Bạn sẽ muốn đảm bảo rằng bạn có các dịch vụ sau đang chạy khi mở ứng dụng Xampp của mình

  1. Cơ sở dữ liệu MySQL
  2. Máy chủ web Apache

Cách lưu trữ dữ liệu biểu mẫu html

Bây giờ chúng ta có thể điều hướng đến



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
0 và tạo cơ sở dữ liệu và bảng

  • Nhấp vào
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    4 và sau đó nhập tên Cơ sở dữ liệu của bạn. Chúng tôi sẽ đặt tên cho cơ sở dữ liệu của chúng tôi là
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    1. Sau khi hoàn thành, hãy tiếp tục và nhấp vào nút
    
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    6

Cách lưu trữ dữ liệu biểu mẫu html

Tiếp theo, chúng ta có thể tạo bảng mà chúng ta muốn sử dụng có tên là



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
2. Đảm bảo đặt số lượng cột thành 5. Sau khi hoàn thành, nhấp vào nút


// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
6

Cách lưu trữ dữ liệu biểu mẫu html

Bây giờ, Cơ sở dữ liệu và bảng Mẫu của chúng tôi đã được tạo, chúng tôi có thể nhập các cột của mình và nhấp vào lưu

Đảm bảo bạn nhập đúng loại dữ liệu cho từng cột

  • 
    
    // Set your connection variables
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    // Create connection
    $conn = new mysqli($servername,
        $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: "
            . $conn->connect_error);
    }
    // Insert into appropriate table
    $sqlquery = "INSERT INTO table VALUES
        ('John', 'Doe', '[email protected]')"
    
    // If the connection is successful, run the query
    if ($conn->query($sql) === TRUE) {
        echo "record inserted successfully";
    
    // If the query is not successful, display the error message
    } else {
        echo "Error: " . $sql . "
    "
    . $conn->error; } ?>
    9
  • 
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
        // collect value of input field
        $data = $_REQUEST['val1'];
    
        if (empty($data)) {
            echo "data is empty";
        } else {
            echo $data;
        }
    }
    
    // Closing the connection.
    $conn->close();
    
    ?>
    
    0
  • 
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
        // collect value of input field
        $data = $_REQUEST['val1'];
    
        if (empty($data)) {
            echo "data is empty";
        } else {
            echo $data;
        }
    }
    
    // Closing the connection.
    $conn->close();
    
    ?>
    
    1
  • 
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
        // collect value of input field
        $data = $_REQUEST['val1'];
    
        if (empty($data)) {
            echo "data is empty";
        } else {
            echo $data;
        }
    }
    
    // Closing the connection.
    $conn->close();
    
    ?>
    
    2
  • 
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
        // collect value of input field
        $data = $_REQUEST['val1'];
    
        if (empty($data)) {
            echo "data is empty";
        } else {
            echo $data;
        }
    }
    
    // Closing the connection.
    $conn->close();
    
    ?>
    
    3

Ngoài ra, hãy nhớ thêm loại



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
4 thích hợp vào từng mục

Cách lưu trữ dữ liệu biểu mẫu html

Tạo biểu mẫu html

Bây giờ là lúc để tạo biểu mẫu HTML của chúng tôi. Chúng tôi sẽ sử dụng biểu mẫu này để gửi dữ liệu đến cơ sở dữ liệu của chúng tôi

tên tệp.



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
5



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
9

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Tạo tập lệnh php

Bây giờ chúng ta cần tạo tập lệnh PHP của mình. Đây là tập lệnh sẽ xử lý dữ liệu biểu mẫu của chúng tôi và chèn nó vào cơ sở dữ liệu của chúng tôi

tên tệp.



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
6



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
1

Vào chế độ toàn màn hình Thoát chế độ toàn màn hình

Tuyệt quá. Bây giờ chúng tôi có thể gửi dữ liệu biểu mẫu của mình tới cơ sở dữ liệu nhưng trước tiên chúng tôi cần lưu các tệp



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
5 và


if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
6 bên trong thư mục


if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
9 nằm trong thư mục Xampp của chúng tôi

Thư mục HTDOCS

Chúng tôi có thể truy cập thư mục này bằng cách mở ứng dụng Xampp của chúng tôi và sau đó nhấp vào



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
90

Cách lưu trữ dữ liệu biểu mẫu html

Thao tác này sẽ mở thư mục tệp Xampp của chúng tôi. Điều hướng đến thư mục



if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
9 và sao chép các tệp


if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
5 và


if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // collect value of input field
    $data = $_REQUEST['val1'];

    if (empty($data)) {
        echo "data is empty";
    } else {
        echo $data;
    }
}

// Closing the connection.
$conn->close();

?>
6 của bạn trực tiếp vào thư mục này. Điều này sẽ ghi đè lên các tập tin hiện có. Bây giờ chúng ta có thể đi đến


// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
94 để điền vào biểu mẫu gửi nó đến cơ sở dữ liệu của chúng ta

Cách lưu trữ dữ liệu biểu mẫu html

Điền vào biểu mẫu và sau đó nhấp vào



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
95. Tuyệt quá. có vẻ như dữ liệu của chúng tôi đã được lưu trữ thành công trong DB của chúng tôi

Cách lưu trữ dữ liệu biểu mẫu html

Đi tới



// Set your connection variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

// Create connection
$conn = new mysqli($servername,
    $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: "
        . $conn->connect_error);
}
// Insert into appropriate table
$sqlquery = "INSERT INTO table VALUES
    ('John', 'Doe', '[email protected]')"

// If the connection is successful, run the query
if ($conn->query($sql) === TRUE) {
    echo "record inserted successfully";

// If the query is not successful, display the error message
} else {
    echo "Error: " . $sql . "
"
. $conn->error; } ?>
0 và chọn cơ sở dữ liệu của bạn để đảm bảo rằng dữ liệu của chúng tôi đã được chèn thành công

Cách lưu trữ dữ liệu biểu mẫu html

Sự kết luận

Bạn vừa hoàn thành các bước cơ bản để lưu trữ dữ liệu trong cơ sở dữ liệu bằng HTML và PHP. Bây giờ bạn có thể sử dụng phương pháp này để tạo bất kỳ loại biểu mẫu nào bạn thích và đính kèm nó vào cơ sở dữ liệu phpMyAdmin


🤝 Xin chân thành cảm ơn quý khách hàng đã dành thời gian đọc bài viết này. Tôi hy vọng nó đã giúp bạn và bạn đã học được điều gì đó mới mẻ ngày hôm nay. Vui lòng để lại nhận xét nếu bạn có bất cứ điều gì bạn muốn thêm. tôi rất muốn nghe từ bạn