Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用复选框更新特定行_Php - Fatal编程技术网

Php 如何使用复选框更新特定行

Php 如何使用复选框更新特定行,php,Php,我试图更新从表单生成的表中的特定行。我正在使用复选框,但整个表正在更新,而不是我正在填写的特定行。我试着设置,看看我是否可以让它只更新时,框被勾选,但没有工作。以下是我所拥有的(显然不是全部代码,但我可以根据需要提供更多): 如果您使用例如StudentId作为学生的标识符,则您必须在查询的末尾添加其中条件,以便仅向上显示所需的行,然后编写: $sql=“更新studentlistSET responsibility='$resp',organization='$org',independent

我试图更新从表单生成的表中的特定行。我正在使用复选框,但整个表正在更新,而不是我正在填写的特定行。我试着设置,看看我是否可以让它只更新时,框被勾选,但没有工作。以下是我所拥有的(显然不是全部代码,但我可以根据需要提供更多):


如果您使用例如
StudentId
作为学生的标识符,则您必须在查询的末尾添加
其中
条件,以便仅向上显示所需的行,然后编写:


$sql=“更新studentlistSET responsibility='$resp',organization='$org',independentwork='$ind',collaboration='$coll',initiative='$init',self Regulation='$self',其中StudentId='$StudentId'

Gadzooks,这是很多回音。对不起,我真的不太清楚你的意思。如果有帮助的话,我添加了更多的代码,但我不确定如何消除所有的回声。
<?php

include 'connect.php';


// All possible parameters
$params = array(
    'Student',
    'homeroom',
    'teacher'

);

$wheres = array();
foreach ($params as $param) {

    // Is the param set?
    // If so, let's add it to our list of WHERE clauses
    if (isset($_GET[$param]) && !empty($_GET[$param])) {
        $wheres[] = sprintf("%s LIKE '%%%s%%'", $param, mysqli_real_escape_string($connect, $_GET[$param]));
    }
}

if ($db_found) {

    // Now let's make the SQL.
    $SQL = 'SELECT * FROM studentlist';

    // We only want to add the WHERE clause if we had some parameters passed
    if (count($wheres) > 0) {
        $SQL .= ' WHERE ' . implode(' OR ', $wheres);
    }



    $result = mysqli_query($connect, $SQL);



    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {

  echo "<tr>";
  echo "<td>" . $row['Student'] . "</td>";
  echo "<td>" . $row['homeroom'] . "</td>";
  echo "<td>" . "<input type='checkbox' name='responsibility' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='responsibility' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='responsibility' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='responsibility' value='N'>" . "</td>";
  echo "<td>" . "" . "</td>";
  echo "<td>" . "<input type='checkbox' name='organization' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='organization' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='organization' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='organization' value='N'>" . "</td>";
  echo "<td>" . "" . "</td>";
  echo "<td>" . "<input type='checkbox' name='independentwork' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='independentwork' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='independentwork' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='independentwork' value='N'>" . "</td>";
  echo "<td>" . "" . "</td>";
  echo "<td>" . "<input type='checkbox' name='collaboration' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='collaboration' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='collaboration' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='collaboration' value='N'>" . "</td>";
  echo "<td>" . "" . "</td>";
  echo "<td>" . "<input type='checkbox' name='initiative' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='initiative' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='initiative' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='initiative' value='N'>" . "</td>";
  echo "<td>" . "" . "</td>";
  echo "<td>" . "<input type='checkbox' name='selfregulation' value='E'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='selfregulation' value='G'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='selfregulation' value='S'>" . "</td>";
  echo "<td>" . "<input type='checkbox' name='selfregulation' value='N'>" . "</td>";

  echo "</tr>"; 
            <?php

        include 'connect.php';



        // Get values from form 
        $resp=$_POST['responsibility'];
        $org=$_POST['organization'];
        $ind=$_POST['independentwork'];
        $coll=$_POST['collaboration'];
        $init=$_POST['initiative'];
        $self=$_POST['selfregulation'];



       // Insert data into mysqli 
       $sql = "UPDATE studentlist 
       SET responsibility='$resp', organization='$org', independentwork='$ind', 
       collaboration='$coll', initiative='$init', selfregulation='$self'";

       $result=mysqli_query($connect, $sql);

       // if successfully insert data into database, displays message "Successful". 
       if($result){
       echo "Successful";


       }

       else {
       echo "ERROR";
       }
       ?> 

<?php 
// close connection 
mysqli_close($connect);
?>