gpt4 book ai didi

php - 使用php从表中删除值

转载 作者:行者123 更新时间:2023-11-30 21:50:27 25 4
gpt4 key购买 nike

我有一个表 (php),每行旁边都有删除按钮。我试图通过提交按钮将行的 id 传递给我的查询。提交时没有错误,但行没有被删除。

这是我的表格的源代码:

<?php
include ("dbh.php");

$sql_showBooking = "SELECT tid, ticket, bk_email, price FROM ticket_purchase";
$result = $conn->query($sql_showBooking);

if ($result->num_rows > 0) {
echo "<table><tr><th>No.</th><th>Ticket</th><th>Email</th><th>Price</th>
<th>Action</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row["tid"]."</td>";
echo "<td>".$row["ticket"]."</td>";
echo "<td>".$row["bk_email"]."</td>";
echo "<td>".$row["price"]."</td>";
echo '<form novalidate="novalidate" role="form" method="post" action="delete.php?id='.$row['tid'].'">
<td><input type="submit" class="btn btn-block" name="btnDelete" value="Delete"/></td>
</from>';
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>

PHP(删除)

<?php
session_start();
include ("dbh.php");

if(isset($_POST["btnDelete"])){

$tid_delete = $_POST ['tid'];

$sql_delete = "delete from ticket_purchase where tid='$tid_delete'";

mysqli_query($conn, $sql_delete);

mysqli_close($conn);

header("Location: Coldplay.php");
}

?>

有什么想法吗?

最佳答案

试试这个...

<?php
include ("dbh.php");

$sql_showBooking = "SELECT tid, ticket, bk_email, price FROM ticket_purchase";
$result = $conn->query($sql_showBooking);

if ($result->num_rows > 0) {
echo "<table><tr><th>No.</th><th>Ticket</th><th>Email</th><th>Price</th>
<th>Action</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>".$row["tid"]."</td>";
echo "<td>".$row["ticket"]."</td>";
echo "<td>".$row["bk_email"]."</td>";
echo "<td>".$row["price"]."</td>";
echo '<td><a href = "delete.php?tid='.$row['tid'].' ">Delete</a></td>'; //change this line
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>


<?php
session_start();
include ("dbh.php");

if(isset($_REQUEST["tid"])){ //change

$tid_delete = $_REQUEST['tid']; //changes

$sql_delete = "delete from ticket_purchase where tid='$tid_delete'";

mysqli_query($conn, $sql_delete);

mysqli_close($conn);

header("Location: Coldplay.php");
}

?>

关于php - 使用php从表中删除值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47523072/

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