duanqiu9104 2015-09-22 07:55
浏览 19
已采纳

PHP数据库删除功能只适用于第一行数据库?

    <p><?php include 'header.php'; ?></p>
    <div align="justify">

        <td>Name:<input type="text" name="password" ></td> <!-- database -->
        <td>&nbsp; Rank:<select>
                <!--<option value="volvo">//Database</option>
                    <option value="saab">Saab</option>
                -->
                <?php
                require ("dbfunction.php");
                $con = getDbConnect();

        <td>&nbsp;<input type="checkbox" name="vehicle" value="Bike">Group by Rank</td> <!-- database -->
        <td>&nbsp;<input type="checkbox" name="vehicle" value="Bike">Include previous service terms</td>  <!-- database -->
    </div>
    <p><table>
        <tr>
            <th>Name</th>
            <th>Rank</th>
            <th>Start Date</th>
            <th>End Date</th>
            <th>Watchkeeping</th>
            <th>Active</th>
            <th></th>
            <th></th>
        </tr> <!-- database -->
        <tr> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <?php
            if (!mysqli_connect_errno($con)) {

                $queryStr = "SELECT * " .
                        "FROM crewlist";
            }
            $result = mysqli_query($con, $queryStr);
            while ($row = mysqli_fetch_array($result)) {
                 //echo "<div><a href=http://localhost/poshproject/crewlisting.php?crew_name={$row["crew_id"]}>";


                echo "<tr>.<th>" . $row["crew_name"] . "<br></br>" . "</th>";
                echo "<th>" . $row["crew_rank"] . "</th>";
                echo "<th>" . $row["start_date"] . "</th>";
                echo "<th>" . $row["end_date"] . "</th>";
                echo "<th>" . $row["watchkeeping"] . "</th>";
                echo "<th>" . $row["active"] . "</th>";
                echo "<td><a href=\"editcrew.php?id=" . $row['crew_id'] . "\">Edit</a>";
                //echo "<td><center><button type=\"submit\" name=\"Delete\" value="' . $row['crew_id'].'"/>Delete</button></center></td>";
                echo "<td><a href=\"delete.php?id=" . $row['crew_id'] . "\">Delete</a>";
            }
            ?>
            <!--                
                            <td><center><button type="submit" value="Edit">Edit</button></center></td>
                    <td><center><button type="submit" value="Delete">Delete</button></center></td>-->
        </form></tr>

    </tr>
</table>
---------------------delete.php---------------------
<?php
//print_r($_GET);
include 'dbfunction.php';
$con = getDbConnect();

if (!mysqli_connect_errno($con)) {
   $queryStr = "SELECT * FROM crewlist";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {
     if (!mysqli_connect_errno($con)) {
        $sqliQueryStr = "DELETE FROM `posh`.`crewlist` WHERE crew_id = ". $row['crew_id'] . "";
                }
      mysqli_query($con, $sqliQueryStr);
      header('Location: crewlisting.php');
      mysqli_close($con);
      //echo "user has been deleted";
   }
 ?>

Delete function only works on first row of database. When I delete the rows that are not the first, it deletes the first row instead. Not sure where the error is when I've tried pretty much everything.

  • 写回答

2条回答 默认 最新

  • dregvw1801 2015-09-22 08:02
    关注

    I think you are wrong on delete.php file. Put below code in your delete.php file.

    ---------------------delete.php---------------------
    <?php
    include 'dbfunction.php';
    $con = getDbConnect();
    
    if (!mysqli_connect_errno($con)) {
        $sqliQueryStr = "DELETE FROM `posh`.`crewlist` WHERE crew_id = " .       $_GET['id'];
        mysqli_query($con, $sqliQueryStr);
    }
    header('Location: crewlisting.php');
    mysqli_close($con);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog