Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:29:31+00:00 2026-06-07T12:29:31+00:00

Tough Time in inserting a query. My form is having 1 question, 4 options

  • 0

Tough Time in inserting a query.

My form is having 1 question, 4 options with radio button in while loop. Questions and options are fetched from table named paper, I used array for question and answers. Below is the code I used.

<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>

Now, submit_answer.php page is for submitting all questions and answers with student std, student name, test name, questions and answers. Below is the code I used:

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();
}

It does insert std of the student but not the rest of the values and gives me error.

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

Table fields are:

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

Kindly help me out in above query. Thanks in Advance!! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:29:32+00:00Added an answer on June 7, 2026 at 12:29 pm

    LOL I got my own answer, query will be as per the below:

    $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();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a real tough time diagnosing a 500 error from my application running
I am having tough time getting to read data from excel 2007. I am
I am having a tough time understanding why the Scala compiler is unhappy about
I'm having a really tough time getting XMPPFramework to work. I've followed every direction
I am reaching a bottleneck on my application and having a tough time finding
I'm pretty new to Backbone and Marionette and am having a tough time getting
I'm without my Java reference book and I'm having a tough time finding an
I'm having tough time connecting flex to MySql through zend php. I saw a
I'm having a tough time consolidating errors in my application. Currently, my error.jsp looks
I have tough time making this design decision. I could go with traditional new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.