title: how to select multiple checkbox and save into my database
body: <p>i have here my representative.php codes which the data are called in my database from a javscript function. when i click my submit button it returns me nothing as i echo the checked persons(representatives). only i know is getting values of multiple checkbox in a static form, but this time it really makes me so confuse for this one is a dynamic. and another thing is how could i save the selected values to my database for i still have no idea of how should i save it.. pls...</p>
  
  <pre><code>&lt;?php session_start(); ?&gt;
  &lt;?php
  
  // server info
  $server = 'localhost';
  $user = 'root';
  $pass = 'root';
  $db = 'user';
  // connect to the database
  $mysqli = new mysqli($server, $user, $pass, $db);
  // show errors (remove this line if on a live site)
  mysqli_report(MYSQLI_REPORT_ERROR);
  ?&gt;
  &lt;?php
  if ($_POST['submit']){
      $check = $_POST['representatives'];
      foreach ($check as $ch){
          echo $ch."&lt;br&gt;";
      }
  
  } ?&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;html&gt;
      &lt;head&gt;  
          &lt;script type="text/javascript"&gt;
          function get_representatives_value()
          {
              for (var i=0; i &lt; document.list.representatives.length; i++)
  
              {
                  if (document.list.representatives[i].checked = true)
                  {
                      var candidate = document.list.representatives[i].checked;
  
                  }
                  document.president.radio[i].value;
              }
          }
          }
          &lt;/script&gt;
          &lt;title&gt;&lt;/title&gt;
  
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
          &lt;link href="candidate.css" rel="stylesheet" type="text/css"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form name="list" action="president2.php" method="post"  onClick="get_president_value"&gt;
              &lt;div id="form"&gt; 
              &lt;?php
              // get the records from the database
              if ($result = $mysqli-&gt;query("SELECT * FROM candidate_info WHERE position= 'representatives' ORDER BY cand_id"))
              {
              // display records if there are records to display
                  if ($result-&gt;num_rows &gt; 0)
                  {
                      // display records in a table
                      echo "&lt;table border='1' cellpadding='10'&gt;";
                      // set table headers
  
                      echo "&lt;tr&gt;&lt;th&gt;Student ID&lt;/th&gt;&lt;th&gt;Candidate ID&lt;/td&gt;&lt;th&gt;Course&lt;/th&gt;&lt;th colspan = '3'&gt;Name&lt;/th&gt;&lt;/tr&gt;";
                      while ($row = $result-&gt;fetch_object())
                      {
                          // set up a row for each record
                          echo "&lt;tr&gt;";
                          echo "&lt;td&gt;" . $row-&gt;cand_studid . "&lt;/td&gt;";
                          echo "&lt;td&gt;".$row-&gt;cand_id."&lt;/td&gt;"; 
                          echo "&lt;td&gt;" . $row-&gt;course . "&lt;/td&gt;";
                          echo "&lt;td coslpan ='5'&gt;" . $row-&gt;fname . " ". $row-&gt;mname ." ". $row-&gt;lname ." &lt;/td&gt;";
                          echo "&lt;td&gt;&lt;input type ='checkbox' name='representatives[]' id='". $row-&gt;studid ."' value='" . $row-&gt;fname . " ". $row-&gt;mname ." ". $row-&gt;lname .  "'onchange='get_representatives_value()' /&gt;&lt;/td&gt;";
                          echo "&lt;/tr&gt;";
                      }
                      cho "&lt;/table&gt;";
                  }
                  // if there are no records in the database, display an alert message
                  else
                  {
                      echo "No results to display!";
                  }
              }
              // show an error if there is an issue with the database query
              else
              {
                  echo "Error: " . $mysqli-&gt;error;
              }
  
              // close database connection
              $mysqli-&gt;close();
              echo "&lt;input type='submit' value='Submit'/&gt;";
              ?&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>heres the preview of my output representative.php. the tab</p>
  
  <p><img src="https://i.stack.imgur.com/eHUBr.jpg" alt="enter image description here"></p>