PHP - 将 HTML 表中的数据插入 MySQL 数据库

问题描述:

我有一个 HTML 表单和一个表格.此预览中删除了提交按钮和其他代码行.代码如下.

I have an HTML form and a table inside it. Submit buttons and other lines of code are removed in this preview. Code below.

<form method="post" action="">
    <table>
        <thead>
            <tr>
                <th>Days</th>
                <th>Price</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input name="days[]" type="text"/></td>
                <td><input name="price[]" type="text"></td>
            </tr>
            <tr>
                <td><input name="days[]" type="text"/></td>
                <td><input name="price[]" type="text"></td>
            </tr>
        </tbody>
    </table>
</form>

链接到图像,表格与表格的外观:

Link to the image, how the form with the table looks:

因此,每当我单击提交按钮时,我都想将表中每一列的数据放入 MySQL 数据库.

So, whenever I click the submit button, I want to put the data of each column from table to MySQL database.

然后我需要在 HTML 表格中显示数据库中的数据,看起来应该像图像中的那样:

Then I need to display that data from database in the HTML table that should look like in the image:

我了解如何从数据库中检索数据并将其输出到表中,但我无法找到如何在单击提交按钮时将每个表的列数据插入到 MySQL 数据库中.

I understand how to retrieve data from database and output it in the table, but I can't find out how to insert every table's column data into MySQL database when I click a submit button.

为每个输入字段提供一个唯一的名称标识符 'name="days_a"',您可以使用它来获取 onSubmit$_POST['days_a'],$_POST['days_b']

Give each input field a unique name identifier 'name="days_a"' which you can get onSubmit using $_POST['days_a'],$_POST['days_b'] etc