-1

这是我的表格,很简单。我有 3 个文本字段,将在其中输入问题,我想将其中的每一个都放入数据库中。

questFormtest.php:

<html>
<head><title> Test Quest</title></head>
<body>
<form id= "qform" method="post" action="quest.php">
<h3>Enter Questions</h3><br><br>
<h3>Question 1: Five marks each.<br></h3>

    a) <input type="text" name="field1[][field1]" size=45>* <br><br>
    b) <input type="text" name="field1[][field1]" size=45>* <br><br>
    c) <input type="text" name="field1[][field1]" size=45>* <br><br>

<p><input  type="submit" name="submit" value="Submit" align="center" />
<input type='reset' name='Cancel' value='Cancel' /></p>
</form>
</body>
</html>


My php file is as follows:

任务.php:

<?php
include('connectionfile.php');
$cnt = count($_POST['field1']);

if ($cnt > 0) {
    $insertArr = array();
    for ($i=0; $i<$cnt; $i++) {
        $insertArr[] = "('" .$_POST['field1'][$i]. "')";
    }

    $query = "INSERT INTO paper (field1) VALUES " . implode(", ", $insertArr);
    mysql_query($query) or trigger_error("Insert failed: " . mysql_error());
}

mysql_close($id_link);
?> 

当我运行该文件时,它给了我以下错误:

Insert failed: Unknown column 'field1' in 'field list' in quest.php on line 15

有人可以告诉我查询中是否有错误以及如何解决?任何帮助表示赞赏:)

4

1 回答 1

1

发布的值在此索引中:$_POST['field1'][$i]['f​​ield1']。因此,您在 for 循环中使用此代码: $insertArr[] = "('" .$_POST['field1'][$i]['f​​ield1']. "')" ;

于 2013-04-03T06:21:13.770 回答