title: Store multiple dropdown selected values in mysql db
body: <p>I have multiple dropdown boxes and I am trying to store the selected values in mysql database and all in one button click. The number of dropdown boxes is determined by the user. I have a jquery function that generates the desired number of dropdowns to display. As mentioned previously , I am trying to store the selected values of each dropdown. Each with its own row and unique id. The query I have is not storing anything at all. <a href="http://webprolearner.ueuo.com/test/index.php" rel="nofollow">SITE</a></p>
  
  <p>Jquery to generate the number of dropdowns</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function () {
  
      $('select').change(function() {
      var option = $(this).val();
      showFields(option);
      return false;
          });
  
  
          function showFields(option){ 
  
              var content = '';
              for (var i = 1; i &lt;= option; i++){
                  content += '&lt;div id="course_'+i+'"&gt;&lt;label&gt;Course # '+i+'&lt;/label&gt;&lt;br /&gt;&lt;label&gt;Course Name:&lt;/label&gt; &lt;select id="coursename_'+i+'" name="coursename_'+i+'"&gt;&lt;option value=""&gt;--- Select ---&lt;/option&gt;"'
                          &lt;?php
  
  
                             $mysqli = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
                             if (mysqli_connect_errno()) {
                                  printf("Connect failed: %s\n", mysqli_connect_error());
                                  exit();
                              } 
                              $course_query = "SELECT course_id, course_name FROM courses ";
                                      if($result = mysqli_query($mysqli, $course_query)) {
                                          while ($idresult = mysqli_fetch_row($result))
                                          {
                                              //dropdown values pulled from database
                                              $course_id = $idresult[0];
                                              $course_name = $idresult[1];
                                              echo 'content += \'&lt;option value="' . $course_id . '"&gt;' . $course_name . '&lt;/option&gt;\';';
                                          }
                                      }
                          ?&gt;
                  '"';                   
  
                  content += '&lt;/select&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;';
  
              }
              $('#course_catalog').html(content);
  
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>PHP Insert</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['submit'])){
  
          $coursename = $_POST["coursename"];
          $courseid = $_POST["courseid"];
  
          $db_con = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
          $db_insert4 = "INSERT INTO courses_bridge (course_name, course_id) VALUES ('$coursename', '$courseid')";
          mysqli_query($db_con, $db_insert4);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;form action="index.php" method="post"&gt;
      Courses being offered?
          &lt;select&gt;
              &lt;option value="1"&gt;1&lt;/option&gt;
              &lt;option value="2"&gt;2&lt;/option&gt;
              &lt;option value="3"&gt;3&lt;/option&gt;
              &lt;option value="4"&gt;4&lt;/option&gt;
              &lt;option value="5"&gt;5&lt;/option&gt;
          &lt;/select&gt;
  
      &lt;div id="course_catalog"&gt;&lt;/div&gt;
  
      &lt;/br&gt;
      &lt;input value="SAVE" type="submit"&gt;
  &lt;/form&gt;
  </code></pre>