Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is my form, a pretty simple one. I have 3 text fields in which questions will be entered and i want to put each of these in a database.

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:

quest.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);
?> 

When i run the file, it gives me the following error:

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

Can somebody tell me if there's an error in the query and how i can solve it? Any help is appreciated :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.8k views
Welcome To Ask or Share your Answers For Others

1 Answer

The posted value is in this index: $_POST['field1'][$i]['field1']. So you use this code : $insertArr[] = "('" .$_POST['field1'][$i]['field1']. "')" in you for loop;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...