duanlinjian5819 2015-09-22 06:19
浏览 20

SQL仅编辑第一个选项

This is the code from our handle page we are trying to edit our database in phpmyadmin but can seem to only edit our first entry even though we clicked on other entries' edit button

require 'dbfunction.php';
$con = getDbConnect();
$crew_id = $_POST["crew_id"];
$CrewName = $_POST["CrewName"];
$CrewRank = $_POST["CrewRank"];
$StartDate = $_POST["StartDate"];
$EndDate = $_POST["EndDate"];
$PayrollNo = $_POST["PayrollNo"];
$EmployeeNo = $_POST["EmployeeNo"];
$WatchKeeping = $_POST["WatchKeeping"];
$Active = $_POST["Active"];
//$Delete = $_POST["Delete"];

if (!mysqli_connect_errno($con)) {

$queryStr = "SELECT crew_id " .
        "FROM crewlist";
}
$result = mysqli_query($con, $queryStr);
while ($row = mysqli_fetch_array($result)) {
if (!mysqli_connect_errno($con)) {
    $sqlQueryStr = "UPDATE crewlist SET crew_name = '$CrewName', crew_rank = '$CrewRank', start_date = '$StartDate' "
            . ", end_date = '$EndDate', payroll_no = '$PayrollNo'"
            . ", employee_no = '$EmployeeNo', watchkeeping = '$WatchKeeping', active = '$Active' WHERE crew_id = " . $row['crew_id'];

    mysqli_query($con, $sqlQueryStr);

    mysqli_close($con);
} else {
    break;
}
header('Location: crewlisting.php');
}

?>

This code only edits the first entry of our database and the rest remains stagnant. This is the code from our edit page

<?php
            if (!mysqli_connect_errno($con)) {

                $queryStr = "SELECT * " .
                        "FROM crewlist";
            }
            $result = mysqli_query($con, $queryStr);
            while ($row = mysqli_fetch_array($result)) {

                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><form action=\"editcrew.php\" method=\"post\"><a href='editcrew.php?del={$row['crew_id']}'>edit</a></form></td>";
                echo "<td><a href=\"editcrew.php?id=" . $row['crew_id'] . "\">Edit</a>";
               echo "<td><form action=\"delete.php\" method=\"post\"><a href='crewlisting.php?del={$row['crew_id']}'>delete</a></form></td>";
            }
            ?>
  • 写回答

2条回答 默认 最新

  • dovs36921 2015-09-22 06:23
    关注

    You are closing your mysqli connection in the first iteration of your loop. Move the mysqli_close($con); behind the loop.

    Edit: And you also redirect to crewlist.php in the loop. If you reformat your indentation of your code, this will get obvious.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看