PHP - 将 HTML 表中的数据插入 MySQL 数据库 [英] PHP - Insert data from HTML table into MySQL database

查看:63
本文介绍了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

这篇关于PHP - 将 HTML 表中的数据插入 MySQL 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆