就是想在本页查询 然后在本页删除某条数据 现在能查询出来 但是删除不了 哪里写的不对?
<code> <div id="div1"> <form method="post"> <input type="text" name="num"> <button type="submit">提交</button> </form> </div> <div id="div2"> <form method="post"> <?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $num=$_POST['num']; $res=$pdo->query("SELECT * FROM class WHERE num=$num"); foreach($res as $v){ echo '<span name="cm">'.$v['comment'].'</span>'.'<button type="submit">删除</button>'.'<br>'; } ?> </form> </div> <?php $pdo2=new PDO("mysql:host=localhost;dbname=t1","root",""); $cm=$_POST['cm']; $sql="delete from table class where comment=$cm"; $res2=$pdo2->exec($sql); ?> </code>
就是想在本页查询 然后在本页删除某条数据 现在能查询出来 但是删除不了 哪里写的不对?
<code> <div id="div1"> <form method="post"> <input type="text" name="num"> <button type="submit">提交</button> </form> </div> <div id="div2"> <form method="post"> <?php $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $num=$_POST['num']; $res=$pdo->query("SELECT * FROM class WHERE num=$num"); foreach($res as $v){ echo '<span name="cm">'.$v['comment'].'</span>'.'<button type="submit">删除</button>'.'<br>'; } ?> </form> </div> <?php $pdo2=new PDO("mysql:host=localhost;dbname=t1","root",""); $cm=$_POST['cm']; $sql="delete from table class where comment=$cm"; $res2=$pdo2->exec($sql); ?> </code>
先把你 delete 的 sql ,echo 出来,看看是不是你想要的结果
然后到 database 去执行,看看有没有效果。
然后还有问题,在排查
$cm写成这样'{$cm}'
你的删除中没有input域,也就没有值提交到表单,所以没东西删除