gpt4 book ai didi

PHP 数据库删除函数只适用于数据库的第一行?

转载 作者:搜寻专家 更新时间:2023-10-30 20:37:48 24 4
gpt4 key购买 nike

    <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.php 文件的看法是错误的。将以下代码放入您的 delete.php 文件中。

---------------------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);

关于PHP 数据库删除函数只适用于数据库的第一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32711401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com