PHP Questions with alternatives
<p>I'm facing a big problem here with PHP and I need your help. I'm creating questions in PHP with alternatives. Each question will have  4 alternatives. Questions will be inserted in a table called questions and all alternatives will be inserted in another table which is called alternatives. Every questions has its own id and even every alternative will have own id too. But every group of alternatives will have question id's too , to know which alternative belongs to which question.  And then I will select them as radio buttons.
For example if we have two questions like</p>

<ol>
<li><p>What's the name of Australian capital city? (Let's say this question have id nr 1)<br/>
A) Sidney<br/>
B) New Delhi<br/>
C) Canberra<br/>
D) Maimi<br/>
And All those alternatives above will have their own id's and questions id with is 1 in this case.<br></p></li>
<li><p>What is 89 + (3*9) (Let's say this question have id nr 3)<br/>
A) 116 <br/>
B) 117<br/>
C) 115<br/>
D) 112<br/></p></li>
</ol>

<p>And All those alternatives above will have their own id's and questions id with is 3 in this case.<br><br>
 3. An object is dropped from the top of a 100-m-high tower. Its height aboveground after t seconds is 100-4.9t2 m. how fast is it failing 2 sec after is it dropped?<br/>
A) 98m<br/>
B) 78m<br/>
C) 56m<br/>
D) None of them<br/>
And so on ..... <br></p>

<p>Here is my code:</p>

<pre><code>if (isset($_REQUEST['submit']) &amp;&amp; $_REQUEST['submit'] != "") {
    $questions = $_POST['questions']; 

    $alternatives = $_POST['alternatives']; 


    if(isset($_POST['questions']) &amp;&amp; $_POST['questions'] != '')
    {

        foreach($questions as $q) {

            if($q !='') {

                $sql1 = " INSERT INTO questions (question) ".
                        " VALUES ('".$q."'); ";
                if (!db_query($sql1)) 
                    $errors['err']='Unable to create question';
                $question_id[] = mysql_insert_id(); 
            }

        }

        foreach($question_id AS $q_id) { // I think here is the problem but I don't know how to solv'

            foreach($alternatives as $alt){


                if($alt !=''){
                    $sql =  " INSERT INTO alternatives (alternative, question_id) ".
                                " VALUES ('".$alt."', ".$q_id."); ";
                                if (!db_query($sql))
                    $errors['err']='Unable to create alternatives';
                 }

            }

        }

    }

}




&lt;form action="test.php" method="POST" enctype="multipart/form-data"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
for($i=1; $i&lt;=10; ++$i){
$i.") "?&gt;&lt;input type="text" name="questions[]" value="" size="100"/&gt;&lt;br /&gt;
&lt;br /&gt;&lt;p&gt;Alternatives:&lt;/p&gt;&lt;br /&gt; 
for($j=1; $j&lt;=4; ++$j){
&lt;input type="text" name="alternatives[]" value="" /&gt;&lt;br /&gt; } }
&lt;input type="submit" name="submit" value="Send"&gt;&lt;/input&gt;
 &lt;input class="button" type="reset" value="Reset" /&gt;

&lt;/form&gt;
</code></pre>

<p>Sorry for my code.. it was very difficult to write on here. But what is happening is  : </p>

<p>All the 12 alternatives are inserted three times and each time they get all the same question_id. I mean the first 12 alternatives get question_id 1 , then those 12 alternatives are inserted again and they get question_id = 2 , and so on.... What I want is the first four alternatives get question_id  1, the alternatives of the second question would have question_id nr 2 and so on. I don't know how to solve it. </p>
