且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用PHP&插入多行的MySQL

更新时间:2023-01-29 20:31:14

请确保您输入的名称唯一.但是您可以像这样命名每列(请参见此处例如)

Be sure you name your inputs uniquely. But you can name every column like this (see here for example):

<input type="text" name="column1[]" />
<input type="text" name="column2[]" />
<input type="text" name="column3[]" />

这样,您可以使用for循环通过PHP访问列.

That way you can access the columns via PHP using a for loop.

for($i = 0; $i < $n; $i++) // If you have $n rows
{
    echo($_POST["column1"][$i]);
    echo($_POST["column2"][$i]);
    echo($_POST["column3"][$i]);
}

要在MySQL数据库中插入多行,请使用以下语法(另请参见:

To insert multiple rows into your mySQL database use the following syntax (also: see here).

INSERT INTO
    tbl_name (column1, column2, column3)
VALUES
    (1,2,3),
    (4,5,6),
    (7,8,9);

现在您应该设置为建立SQL查询.

Now you should be set to build your SQL query.