gpt4 book ai didi

php - 无法使用sql删除表中的数据

转载 作者:行者123 更新时间:2023-11-29 04:05:42 26 4
gpt4 key购买 nike

我正在尝试从表中删除行。表名是用户的用户名(哪个用户登录)

删除页面在这里

require('db.php');
if(isset($_POST["deletebtn"])){
$x = $_SESSION['username'];
$id=$_POST["statusid"];
$row=$conn->query("select id from $x where id='$id'");
if ($conn->query($row) === TRUE) {
$sql = "delete from $x where id ='$id'";
// echo 'success';
header( "Refresh:3; url=admin2.php", true, 303);
}else{
echo "not";
}
}

这是我的内容代码

$sql = "SELECT id,date,status FROM $x order by id DESC;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
echo "<div class='border'> ";
echo "";
echo "<form action='deletepage.php?action=$id'>";
echo "<input type='hidden' name='statusid' value='$id' >";
echo "<p> " . $row["status"] ."</p><br>";
echo "<input type='submit' value='delete' class='btn1 pull-right' name='deletebtn'> ";
echo "<a class=' btn1 pull-right' href='#'>edit &nbsp;&nbsp;</a>";
echo "<small> " . $row["date"]. "</small><br>";
echo "</form>";
echo "</div>";
}
} else {............}

最佳答案

你没有在sql上执行查询

$sql = "delete from $x where id ='$id'";

像这样执行

$del= $conn->query($sql);

查询后

关于php - 无法使用sql删除表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42594287/

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