0

クエリを挿入するのに苦労しました。

私のフォームには1つの質問があり、whileループにラジオボタンが付いた4つのオプションがあります。質問とオプションはpaperという名前のテーブルから取得されます。質問と回答には配列を使用しました。以下は私が使用したコードです。

<form id="form1" action="submit_answer.php" method="post">
<?php
$get_question = mysql_query("select * from paper where test_name='$test_name' ORDER BY RAND()");
$count = 0;
$sr = 1;
if(mysql_num_rows($get_question)==0)
{
    echo "No Questions Found For ".$test_name;
}
else
{
    while($row_question = mysql_fetch_array($get_question))
    {
        $id = $row_question["id"];
        $question = $row_question["question"];
        $option1 = $row_question["option1"];
        $option2 = $row_question["option2"];
        $option3 = $row_question["option3"];
        $option4 = $row_question["option4"];
        $answer = $row_question["answer"];

        echo '<div class="question_box">
                <p>'.$sr.'. '.$question.'</p>
                <div style="margin:10px 0 0 10px;">

                    <input type="text" value="'.$std.'" name="std" />
                    <input type="text" value="'.$student_name.'" name="student_name" />
                    <input type="text" value="'.$test_name.'" name="test_name" />
                    <input type="text" value="'.$question.'" name="question[]" />
                    <input type="hidden" value="'.$answer.'" name="true_answer[]" />
                    <input type="radio" class="answers" name="given_answer['.$count.']" value="A" />&nbsp;'.$option1.'<br/>
                    <input type="radio" class="answers" name="given_answer['.$count.']" value="B" />&nbsp;'.$option2.'<br/>
                    <input type="radio" class="answers" name="given_answer['.$count.']" value="C" />&nbsp;'.$option3.'<br/>
                    <input type="radio" class="answers" name="given_answer['.$count.']" value="D" />&nbsp;'.$option4.'<br/>
                    <input checked="checked" type="radio" class="answers" name="given_answer['.$count.']" value="NONE" style="display:none;" />
                </div>
        </div>';
        $count++;
        $sr++;
    }
}
?>
    <button class="stdbtn btn_black" style="opacity: 1;" type="button" onclick="submit_exam();">Submit</button>
</form>

現在、submit_answer.phpページは、学生の標準、学生の名前、テスト名、質問と回答を含むすべての質問と回答を送信するためのものです。以下は私が使用したコードです:

foreach($_POST as $key => $value)
{
    echo $key;
    echo "<br />";
    print_r($value);
    echo "<br />";
    echo "<br />";

    mysql_query("insert into student_answer($key) values($value)");

    echo mysql_error();
}

学生の標準を挿入しますが、残りの値は挿入せず、エラーが発生します。

**Unknown column 'Array' in 'field list'**

テーブルフィールドは次のとおりです。

+------++--------------++-----------++----------++--------------+
| std  || student_name || test_name || question || given_answer |
+------++--------------++-----------++----------++--------------+

上記のクエリで私を助けてください。前もって感謝します!!:)

4

3 に答える 3

0

配列パラメータとして使用$given_answerしたので、arrayinを返し$keyます。非表示のパラメータカウントを使用してから、を挿入してみてください$key[$count]

于 2012-07-11T08:00:28.417 に答える
0

笑私は自分の答えを得ました、クエリは以下のようになります:

$count = $_POST["count"];    // hidden value under the while loop

for($i=1; $i<=$count; $i++)
{
   $test_name = $_POST["test_name"];
   $std = $_POST["std"];
   $student_name = $_POST["student_name"];
   $question = $_POST["question"][$i-1];
   $given_answer = $_POST["given_answer"][$i-1];

   mysql_query("insert into student_answer(std,student_name,test_name,question,given_answer) values('$std','$student_name','$test_name','$question','$given_answer')");

    echo mysql_error();

}
于 2012-07-12T05:15:03.307 に答える
0

その出発点として、市場で入手可能なオンラインスクリプトを購入することをお勧めします。これにより、時間、コスト、およびテストの労力を節約できます。

以下は、私がそれを実行したすばらしいスクリプトの1つであり、魅力のように機能しました。これをベースとして、コンピューター適応型テストを使用して、1000人を超えるユーザーのオンラインテストポータルを開発しました。

http://codecanyon.net/item/online-skills-assessment/9379895

これは、オンライン試験システムの開発を検討している人々にとって良い出発点です。

于 2014-12-05T06:23:31.433 に答える