Php MySQL insert-来自使用名称数组的输入的值。(菲律宾)

Php MySQL insert-来自使用名称数组的输入的值。(菲律宾),php,mysql,arrays,post,insert,Php,Mysql,Arrays,Post,Insert,我目前正在通过mysql/php生成一个表单。我有超过1500个具有唯一值的输入,我想将它们插入mysql表(1个值/行) 我以这种方式创建表单: echo "<input type='text' name='combination[]' value='justsometext". $row['name'] ."'><br />"; 提交表单后请尝试以下代码: extract($_POST); foreach ($combination as $comb) {

我目前正在通过mysql/php生成一个表单。我有超过1500个具有唯一值的输入,我想将它们插入mysql表(1个值/行)

我以这种方式创建表单:

echo "<input type='text' name='combination[]' value='justsometext". $row['name'] ."'><br />";

提交表单后请尝试以下代码:

extract($_POST);
foreach ($combination as $comb) {
    //if your table has only one field inside:
    $query = mysql_query("INSERT INTO tablename VALUES('".$comb."')");
}
另一个想法的另一个例子以及表格:

<?php
if( isset($_POST['btnsubmit']) ){
    extract($_POST);
    foreach ($sample as $samp) {
        $query = mysql_query("INSERT INTO tablename VALUES('".$samp."')");
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sample</title>
</head>
<body>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
        <input type="text" name="sample[]" value="hello1"><br>
        <input type="text" name="sample[]" value="hello2"><br>
        <input type="text" name="sample[]" value="hello3"><br>
        <input type="text" name="sample[]" value="hello4"><br>
        <input type="text" name="sample[]" value="hello5"><br>
        <input type="submit" name="btnsubmit" value="Submit">
    </form>
</body>
</html>
首先:

第二:1500个输入?哇!您必须仔细检查您的
php.ini
配置是否能够处理它

如果你真的想把1500个值放在一个列中,也许你应该考虑<代码>序列化< /Cord>数组并保持这样的方式?

在准备好的声明中,如下所示:

$combinations = serialize($_POST['combination']);

$q = mysqli_prepare($con, 'INSERT INTO alphabet_combination (combination) VALUES (?)');
mysqli_stmt_bind_param($q, 's', $combinations);
mysqli_stmt_execute($q);
如果您希望为每个值插入一个
插入
,那么在数据库中提交后,将出现下一个
1500
行:

$q = mysqli_prepare($con, 'INSERT INTO alphabet_combination (combination) VALUES (?)');
mysqli_stmt_bind_param($q, 's', $combination);

foreach ($_POST['combination'] as $combination) {
    mysqli_stmt_execute($q);
}

听起来像是个可怕的主意,1500条信息输入到一列?你想用这个实现什么?为什么你有1500个输入?你必须认为betterI是根据另一个数据库的值生成这些输入的,所以每个输入都有不同的值。我有一个名为composition的列,我希望每个输入值都存储在其中,因此基本上1500个输入将生成1500行不同的值。首先,删除分号后面的
。(即时错误抛出)我不知道为什么要在这里添加它,它在我的表单中不存在。这似乎是可行的,但它只是插入了最后一次输入的值。因此,我最终得到1499行,其中有一个0,第1500行有正确的值,即thistextwascombined。
$q = mysqli_prepare($con, 'INSERT INTO alphabet_combination (combination) VALUES (?)');
mysqli_stmt_bind_param($q, 's', $combination);

foreach ($_POST['combination'] as $combination) {
    mysqli_stmt_execute($q);
}