title: Insert data from multiple textfields into MYSQL Database
body: <p>Basically, I am able to display the DIVs based on the selection of drop box. now my problem is : 
  I am able to insert data when there is only single text field. When there are 2 text fields, the submission is a success, but the data cannot be found in the database. 1 row in the database is taken though. </p>
  
  <pre><code>&lt;?php
  //database
  $connection = mysql_connect("localhost", "root", "") or die (mysql_error());
  mysql_select_db("survey" , $connection) or die (mysql_error());
  
  if(isset($_POST['submit'])){
  
  $surveyID =$_POST['surveyCategory'];
  
  for($i=0; $i&lt;count($_POST['id']); $i++){
          $questionID = $_POST['id'][$i];
          $answer = mysql_real_escape_string(htmlspecialchars($_POST['answer'][$i]));
          mysql_query("INSERT INTO answers(survey_id, question_id, answer_body) VALUES   ('$surveyID', '$questionID', '$answer')") or die (mysql_error());
  }
  }
  
  
  
  ?&gt;
  
  &lt;style&gt;
  div{
      display: none;
  }
  &lt;/style&gt;
  
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;form name=displayQuestion method="post"&gt;
      Survey Categories : 
      &lt;select name="surveyCategory" id="surveyCategory"&gt;
      &lt;option&gt; Choose Survey Category &lt;/option&gt;
      &lt;?php
          $surveyQuery = "SELECT survey_id, survey_name FROM surveys";
          $result = mysql_query($surveyQuery) or die (mysql_error());
          while($menu=mysql_fetch_assoc($result)){
          echo "&lt;option value=$menu[survey_id]&gt;$menu[survey_name]&lt;/option&gt;";              
          }
      ?&gt;
      &lt;/select&gt;
  
  &lt;!-- if selection is auction --&gt;
  &lt;div id="1" style="display:none"&gt;
      &lt;?php
      $auctionSurvey = "SELECT question_id, survey_id, question_body FROM questions 
                        WHERE survey_id='1'";
      $aucResult = mysql_query($auctionSurvey) or die (mysql_error());
  
      while($auctionRow = mysql_fetch_assoc($aucResult)){
          echo $auctionRow['question_body'] . "&lt;input type=text name=answer[]&gt;&lt;BR&gt;";?&gt;
          &lt;input type="hidden" name="id[]" value="&lt;?php echo $auctionRow['question_id']?&gt;"&gt;
          &lt;?php
      }
      ?&gt;
  
  &lt;input type="submit" name="submit" value="Submit"&gt;
  &lt;/div&gt;
  
      &lt;!-- if selection is Competition --&gt;
      &lt;div id="2"&gt;
          &lt;?php
          $compSurvey = "SELECT survey_id, question_body FROM questions 
                         WHERE survey_id='2'";
          $compResult = mysql_query($compSurvey) or die (mysql_error());
          while($compRow = mysql_fetch_assoc($compResult)){
              echo "$compRow[question_body]" . "&lt;input type=text   name=&gt;&lt;BR&gt;";
          }
          ?&gt;
          &lt;input type="hidden" name="id" value="&lt;?php echo "$compRow [question_id]"?&gt;"&gt;
          &lt;input type="submit" name="submit" value="Submit"&gt;
      &lt;/div&gt;
  
  
      &lt;!-- if selection is Gallery --&gt;
      &lt;div id="3"&gt;
          &lt;?php
              $gallerySurvey = "SELECT survey_id, question_body FROM questions 
                                WHERE survey_id='3'";
              $galleryResult = mysql_query($gallerySurvey) or die  (mysql_error());
              while($galleryRow = mysql_fetch_assoc($galleryResult)){
                  echo " $galleryRow[question_body]" . "&lt;input   type=text name=answer&gt;&lt;BR&gt;";
              }
          ?&gt;
          &lt;input type="hidden" name="id" value="&lt;?php echo "$galleryRow [question_id]"?&gt;"&gt;
          &lt;input type="submit" name="submit" value="Submit"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script&gt;
  document.getElementById('surveyCategory').onchange = function() {
  var i = 1;
  var myDiv = document.getElementById(i);
  while(myDiv) {
      myDiv.style.display = 'none';
      myDiv = document.getElementById(++i);
  }
  document.getElementById(this.value).style.display = 'block';
  };
  &lt;/script&gt;
  </code></pre>