这是我们的句柄页面中的代码,我们试图在phpmyadmin中编辑我们的数据库,但即使我们点击了其他条目,它们似乎也只能编辑我们的第一个条目。编辑按钮
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');
}
?>
此代码仅编辑数据库的第一个条目,其余的仍然停滞不前。这是我们编辑页面中的代码
<?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>";
}
?>
答案 0 :(得分:1)
您正在循环的第一次迭代中关闭mysqli连接。将mysqli_close($con);
移到循环后面。
编辑:你还可以在循环中重定向到crewlist.php。如果你重新格式化你的代码缩进,这将是显而易见的。
答案 1 :(得分:0)
从循环中删除mysqli_close($con)
:
while ($row = mysqli_fetch_array($result)) {
$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);
}
header('Location: crewlisting.php');