ここにチェックボックスに関するコードがありますが、送信ボタンをクリックするとエラーが発生します。チェックボックスで選択したすべての値を出力しますが、SQLスクリプトで「警告:mysqli_query()には少なくとも2つのパラメーターが必要です。1つはC:\ xampp\htdocs\project\candidate\president2.phpで指定されています」というエラーが表示されました21行目」。選択した値をデータベースに保存したいだけです。助けてください..
         <?php session_start(); ?>
         <?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);
           ?>
           <?php
           if ($_POST['representatives']){
         $check = $_POST['representatives'];
         foreach ($check as $ch){
           //this is my line 21 error. what i want here is to save the selected checkbox into my database but i got some error and i couldnt save it to my database
         mysqli_query("INSERT INTO sample (name) VALUES ('". $ch ."') ");
            echo  $ch. "<br>";
            }
            }
           ?>
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
      <html>
     <head>  
        <script type="text/javascript">
        <!--
    function get_representatives_value()
     {
      for (var i=0; i < document.list.representatives.length; i++)
      {
     if (document.list.representatives[i].value = true)
    {
    return document.getElementById('txt').innerHTML =document.list.representatives[i].value
    }
     }
     }
   //-->
    </script>
  title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <link href="candidate.css" rel="stylesheet" type="text/css">
   </head>
   <body> <p id="txt"></p>
   <form name="list" action="president2.php" method="post" onSubmit="return get_representatives_value()">
<div id="form"> 
     <?php
    // get the records from the database
     if ($result = $mysqli->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->num_rows > 0)
          {
           // display records in a table
        echo "<table border='1' cellpadding='10'>";
         // set table headers
         echo "<tr><th>Student ID</th><th>Candidate ID</td><th>Course</th><th colspan = '3'>Name</th></tr>";
        while ($row = $result->fetch_object())
                  {
         // set up a row for each record
        echo "<tr>";
      echo "<td>" . $row->cand_studid . "</td>";
  echo "<td>".$row->cand_id."</td>";
 echo "<td>" . $row->course . "</td>";
     echo "<td coslpan ='5'>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
  echo "<td><input type ='checkbox' name='representatives[]' id='". $row->studid ."' value='" . $row->fname . " ". $row->mname ." ". $row->lname .  "'onchange='get_representatives_value()' /></td>";
 echo "</tr>";
                                    }
echo "</table>";
                            }
         // 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->error;
                    }
           // close database connection
           $mysqli->close();
    echo "<input type='submit' name='representatives  value='Submit' />";
       ?> 
   </div>
 </form>
    </body>
   </html> 
私の出力のプレビューです。最初の写真は 2 つの候補を選択したもので、もう 1 つは 1 つです。

