猿问

我在每一行上都有批准按钮,单击它后,它应更新数据库中该特定行的批准状态

我是displaying一张桌子,桌子的每一行都有approve和拒绝button,单击批准后的状态应该为reflect to database as approved。


我尝试过,但是单击任何行的批准按钮后,它将被设置status为所有行的批准状态。


我的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>

将所有行的状态设置为已批准


千巷猫影
浏览 118回答 2
2回答

一只萌萌小番薯

我认为您的查询有问题。它没有针对数据库表文件中的正确值。应该是这样的:if(isset($_POST['approve']))&nbsp;&nbsp; $q = "update files set Status='APPROVED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";elseif(isset($_POST['reject']))&nbsp; $q = "update files set Status='REJECTED' where receiver='{$r['receiver']}' and sender='{$r['sender']}' and file='{$r['file']}'";$res = mysqli_query($conn,$q);
随时随地看视频慕课网APP
我要回答