Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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 我在每一行上都有approve按钮,点击它后,它应该会在数据库中更新该特定行的状态为approved_Php - Fatal编程技术网

Php 我在每一行上都有approve按钮,点击它后,它应该会在数据库中更新该特定行的状态为approved

Php 我在每一行上都有approve按钮,点击它后,它应该会在数据库中更新该特定行的状态为approved,php,Php,我正在显示一个表,表的每一行都有一个“批准”和“拒绝”按钮,单击“批准”后,状态应反映为“已批准” 我试过了,但是在点击任何一行的approve按钮后,它会将所有行的状态设置为approved 我的PHP代码是: $doc_re = "select * from files where receiver='$user'"; $record = mysqli_query($conn,$doc_re); if($record) { echo " <br><center&g

我正在显示一个表,表的每一行都有一个“批准”和“拒绝”按钮,单击“批准”后,状态应反映为“已批准”

我试过了,但是在点击任何一行的approve按钮后,它会将所有行的状态设置为approved

我的PHP代码是:

$doc_re = "select * from files where receiver='$user'";
$record = mysqli_query($conn,$doc_re);

if($record)
{
    echo " <br><center><span class='badge badge-light' style='font-size:30px; background-color:teal;color:white;padding:10px;'>RECEIVED RECORDS</span></center>";
    echo "<br><table class='table' border='3' style='background-color:rgba(2,2,2,0.7);'>";
    echo "<thead class='thead-dark' >";
    echo "<tr style='font-size:23px;'><th style='color:skyblue;'><center>TO</center></th>
          <th style='color:skyblue;'><center>FROM</center></th>
          <th style='color:skyblue;'><center>FILE</center></th>
          <th style='color:skyblue;'><center>MESSAGE</center></th>
          <th style='color:skyblue;'><center>APPROVE</center></th>
          <th style='color:skyblue;'><center>REJECT</center></th>
          <th style='color:skyblue;'><center>STATUS</center></th></tr></thead>";

    while($r = mysqli_fetch_array($record,MYSQLI_ASSOC))
    {
        echo "<tr><td style='color:white; font-size:18px;'><center><strong>{$r['receiver']}</strong></center></td>
            <td style='color:white; font-size:18px;'><center><strong>{$r['sender']}</strong></center></td>
            <td style='color:white; font-size:18px;'><center><strong><a href='".$r['file']."'>{$r['file']}</a></strong></center></td>
            <td style='color:white; font-size:18px;'><center><strong>{$r['message']}</strong></center></td>
            <form method='POST'>
            <td><center>
            <button class='button button1' name='approve'  type='submit'><span>&#10003;</span></button></center></td>
            <td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><span>&#10008;</span></button></center></td>
            </form>
            <td style='color:white; font-size:18px;'><center><strong>{$r['Status']}</strong></center></td>
        </tr>";

        if(isset($_POST['approve']))
        {   
            $q1 = "update files set Status='APPROVED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' ";
            $res = mysqli_query($conn,$q1);
        }
        elseif(isset($_POST['reject']) )
        {
            $q2 = "update files set Status='REJECTED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' ";
            $ress = mysqli_query($conn,$q2);
        }   

    }
    echo "</table>";
} 
它将所有行的状态设置为“已批准”

您选择的行可能具有id,因此您可以使用此id传递到查询,并将状态设置为“批准”或“拒绝”,如下所示:

 <td><center>
        <button class='button button1' name='approve'  type='submit'><a href="yourphp.page?status=approved&id=<?php echo $r['id'];?>"><span>&#10003;</span></a></button></center></td>
                <td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><a href="yourphp.page?status=reject&id=<?php echo $r['id'];?>"><span>&#10008;</span></a></button></center></td>
$status=$_GET['status'];//will give you status
$id=$_GET['id'];//will give you id of row selected
 $q1 = "update files set Status='$status' where id=$id";
            $res = mysqli_query($conn,$q1);
在查询中传递上述值,如下所示:

 <td><center>
        <button class='button button1' name='approve'  type='submit'><a href="yourphp.page?status=approved&id=<?php echo $r['id'];?>"><span>&#10003;</span></a></button></center></td>
                <td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><a href="yourphp.page?status=reject&id=<?php echo $r['id'];?>"><span>&#10008;</span></a></button></center></td>
$status=$_GET['status'];//will give you status
$id=$_GET['id'];//will give you id of row selected
 $q1 = "update files set Status='$status' where id=$id";
            $res = mysqli_query($conn,$q1);
上面的查询将用状态更新该特定行。然后在执行查询后,您可以重定向到同一页。表所在的位置。希望这有帮助

注意:使用它也是安全的

您选择的行可能具有id,因此您可以使用此id传递到查询,并将您的状态设置为“批准”或“拒绝”,如下所示:

 <td><center>
        <button class='button button1' name='approve'  type='submit'><a href="yourphp.page?status=approved&id=<?php echo $r['id'];?>"><span>&#10003;</span></a></button></center></td>
                <td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><a href="yourphp.page?status=reject&id=<?php echo $r['id'];?>"><span>&#10008;</span></a></button></center></td>
$status=$_GET['status'];//will give you status
$id=$_GET['id'];//will give you id of row selected
 $q1 = "update files set Status='$status' where id=$id";
            $res = mysqli_query($conn,$q1);
在查询中传递上述值,如下所示:

 <td><center>
        <button class='button button1' name='approve'  type='submit'><a href="yourphp.page?status=approved&id=<?php echo $r['id'];?>"><span>&#10003;</span></a></button></center></td>
                <td><center><button class='button button1' style='background-color:red;' name='reject' type='submit'><a href="yourphp.page?status=reject&id=<?php echo $r['id'];?>"><span>&#10008;</span></a></button></center></td>
$status=$_GET['status'];//will give you status
$id=$_GET['id'];//will give you id of row selected
 $q1 = "update files set Status='$status' where id=$id";
            $res = mysqli_query($conn,$q1);
上面的查询将用状态更新该特定行。然后在执行查询后,您可以重定向到同一页。表所在的位置。希望这有帮助


注意:使用它也是安全的

我认为您的查询有问题。它没有针对数据库中表文件中的正确值。应该是这样的:

if(isset($_POST['approve'])) 
  $q = "update files set Status='APPROVED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";
elseif(isset($_POST['reject']))
  $q = "update files set Status='REJECTED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";

$res = mysqli_query($conn,$q);

我想你的提问有问题。它没有针对数据库中表文件中的正确值。应该是这样的:

if(isset($_POST['approve'])) 
  $q = "update files set Status='APPROVED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";
elseif(isset($_POST['reject']))
  $q = "update files set Status='REJECTED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";

$res = mysqli_query($conn,$q);

我可以获取状态和id作为输入吗?以及如何以及在何处使用id当您单击按钮使用时,您可以传递这些值,然后您需要在查询中传递该id,即:where子句,您可以在我的上述答案中看到。此外,必须有您从表中检索到的每一行的id,以便仅在此处使用,它们对于每一行都是唯一的,很高兴在此单击勾号符号接受此答案,如果它对您有帮助的话:我可以获取状态和id作为输入吗?以及如何以及在何处使用id当您单击按钮使用时,您可以传递这些值,然后您需要在查询中传递该id,即:where子句,您可以在我的上述答案中看到。此外,必须有您从表中检索到的每一行的id,以便仅在此处使用,它们对于每一行都是唯一的,请单击勾号符号接受此答案,如果它有助于您: