how to insert multiple values of array checkbox in one row with different field name
<p>i will use my old posted codes, coz i am working on the same program. what i want is how could i make it possible to save all selected values in one row which the studentid of a user will not be repeated. pls help... </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
     $_SESSION['username'];
     $voter = $_SESSION['username'];
    echo 'Student ID: '. $voter.'';
     echo "&lt;br /&gt;";
       if ($_POST['representatives']){
     $check = $_POST['representatives'];
     foreach ($check as $ch){
      global $voter;
      $mysqli-&gt;query("INSERT INTO sample (studentid, candidate1) VALUES ('".$voter."', '". $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;
    &lt;!--
function get_representatives_value()
 {
  for (var i=0; i &lt; document.list.representatives.length; i++)

  {
 if (document.list.representatives[i].checked)
 {
 return document.getElementById('candidates').innerHTML = document.list.representatives[i].value

 }
 }
 }

 //--&gt;
&lt;/script&gt;
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;p id="txt"&gt;&lt;/p&gt;
&lt;form name="list" action="president2.php" method="post" onSubmit="return get_representatives_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' AND department ='CCEITE' 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;cand_studid ."' value='" . $row-&gt;cand_studid . "' onchange='get_representatives_value()' /&gt;&lt;/td&gt;";
  echo "&lt;/tr&gt;";
                                }
 echo "&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' name='representatives  value='Submit' /&gt;";

   ?&gt; 
  &lt;/div&gt;
 &lt;/form&gt;
 &lt;table&gt;
 &lt;tr&gt;&lt;td&gt;Preview List&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;Candidates: &lt;/td&gt;&lt;td id="candidates"&gt; &lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
 &lt;/html&gt; 
</code></pre>

<p>this the preview of my output and selected checkbox</p>

<p><img src="http://i.stack.imgur.com/C0hB9.jpg" alt="enter image description here"></p>

<p>now this is the preview of my database. this one is the result of my selection from the above preview which the student ID is repeated on my table.</p>

<p><img src="http://i.stack.imgur.com/vYSP2.jpg" alt="enter image description here"></p>

<p>what i want is to save like this</p>

<p><img src="http://i.stack.imgur.com/JoACK.jpg" alt="enter image description here"></p>

<p>and one more thing, how could i make a preview of all i selected on the checkboxes, here is my preview output, below the table is the preview list of candidates as the user click on the checkbox. but it returns only one and only the last selected value as selecting multiple checkboxes will be printed. how could i apply this method in an array coz this preview, i remove the '[]' on my input type name='representative' and it works, but not in the presence of '[]'. </p>

<p><img src="http://i.stack.imgur.com/b7JwB.jpg" alt="enter image description here"></p>
