我正在尝试从表中删除行。
表名是用户的username
(用户登录)
删除页面在这里
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 </a>";
echo "<small> " . $row["date"]. "</small><br>";
echo "</form>";
echo "</div>";
}
} else {............}
答案 0 :(得分:5)
您没有在sql上执行查询
$sql = "delete from $x where id ='$id'";
像
一样执行$del= $conn->query($sql);
查询后
答案 1 :(得分:2)
您忘记执行查询
require'db.php';
if(isset($_POST["deletebtn"])){
$x = $_SESSION['username'];
$id=$_POST["statusid"];
$row="select id from $x where id='$id'"; //<---remove query execution from here
if ($conn->query($row) === TRUE) {
$sql = "delete from $x where id ='$id'";
$conn->query($sql); //<-------- Add this line
// echo 'success';
header( "Refresh:3; url=admin2.php", true, 303);
}else{
echo "not";
}
}
答案 2 :(得分:0)
您的代码存在一些问题。
删除查询没有执行查询。(稍后可能会解决)
在你的while循环中放入$ conn-&gt;查询($ row)这是错误的。 $ row不是查询...它是从先前查询返回的结果集。
最后$ conn-&gt;查询在SELECT,SHOW,DESCRIBE或EXPLAIN查询中不返回true。 Check php manual
答案 3 :(得分:-1)
改变这个
$sql = "delete from $x where id ='$id
为$sql = "delete from $table where id ='$sessionid'