Multiple Array insert from dynamic form
<p>I have been trying to work with this code to get two arrays to insert into the sql db.    The data is coming from a form that is generated from an sql table.  My original intention was to update a the table where the form was generated from questions and answers. However I beleive it would be easier to just insert them into a new table and when the info is needed I can call from that table. Either way though there are two important piecesofinformationthat hae to be transfered and line up exactly.  Those are the row in which the question is from and the interview id that the question is being attached to.  Here is my code.</p>

<pre><code> $result = mysql_query("SELECT * FROM interviews WHERE id='$int'");
                        while($row = mysql_fetch_array($result)){ $a = $row[1]; $b =   $row[2]; $c = $row[3]; $d = $row[4]; $e = $row[5]; $f = $row[7]; $g = $row[8]; $h = $row[9]; }

                    $i = array();   
                    $result = mysql_query("SELECT * FROM dbinter WHERE interview_id='$int'");
                        while($row = mysql_fetch_array($result)){ $i[] = $row[2]; }

                    $l = array();   
                    $result = mysql_query("SELECT * FROM form_custom WHERE attached='$cid' &amp;&amp; date='$e'");
                        while($row = mysql_fetch_array($result)){ $l[] = $row[0]; }

                    echo "&lt;font style='font-size: 45px;'&gt;$a $b&lt;/font&gt;";

                                    echo "&lt;p&gt;&lt;font style='font-size: 20px;'&gt;$c
                                    &lt;br /&gt;$d&lt;/font&gt;&lt;/p&gt;";

                    echo "&lt;form method='POST' name='interview' action='interviewsheet.php?cid=$cid&amp;int=$int&amp;stat=proc'&gt;";
                    echo "&lt;div style='margin-top:50px;'&gt;&lt;input type='submit' value='COMPLETE INTERVIEW'&gt;&lt;/div&gt;";

                    foreach($i as $j){
                    $result = mysql_query("SELECT * FROM form WHERE id='$j'");
                    while($row = mysql_fetch_array($result)){ $k = $row[2]; $p = $row[0];}
                    echo "
                    &lt;div style='margin: 20px;'&gt;
                    &lt;font styler='font-size: large; font-weight: bold;'&gt;$k&lt;/font&gt;&lt;br /&gt;
                    &lt;textarea rows='5' cols='60' style='border: none;' name='q'&gt;&lt;/textarea&gt;
                    &lt;input type='hidden' name='qid' $value='$p'&gt;
                    &lt;/div&gt;
                    ";}

                    foreach($l as $m){
                    $result = mysql_query("SELECT * FROM form_custom WHERE id='$m'");
                    while($row = mysql_fetch_array($result)){ $n = $row[2]; $q = $row[0];}
                    echo "
                    &lt;div style='margin: 20px;'&gt;
                    &lt;font styler='font-size: large; font-weight: bold;'&gt;$n&lt;/font&gt;&lt;br /&gt;
                    &lt;textarea rows='5' cols='60' style='border: none;' name='qc'&gt;&lt;/textarea&gt;
                    &lt;input type='hidden' name='qcid' $value='$q'&gt;
                    &lt;/div&gt;
                    ";}
                    echo "&lt;/div&gt;";
</code></pre>

<p>}</p>

<p>the other code for the processing page is:</p>

<pre><code>    $a = array();
    $a[] = $_POST['q'];
    $b = array();
    $b[] =$_POST['qc'];
    $e = array();
    $e[] = $_POST['qid'];
    $f = array();
    $f[] = $_POST['qcid'];

    $frm = "f";
    $frmc = "fc";


    foreach($a as $key=&gt;$value){
        $avalue = mysql_real_escape_string($value);
        $evalue = mysql_real_escape_string($e[$key]);
        $sql = "INSERT INTO answers (qid,cid,inta,frm,ans) VALUES ('$evalue','$cid','$int','$frm','$avalue')";
                if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}
    }

    foreach($b as $key=&gt;$value){
        $bvalue = mysql_real_escape_string($value);
        $fvalue = mysql_real_escape_string($f[$key]);
        $sql = "INSERT INTO answers (qid,cid,inta,frm,ans) VALUES ('$fvalue','$cid','$int','$frmc','$bvalue')";
                if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}
    }





    header("Location: hr.php?act=int&amp;stat=pend");

    }
</code></pre>
