Why can't I delete the data?

WBOY
Release: 2016-08-18 09:15:43
Original
1479 people have browsed it

I just want to query on this page and then delete a certain piece of data on this page. Now I can query it but I can’t delete it. What’s written wrong?

<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>
Copy after login
Copy after login

Reply content:

I just want to query on this page and then delete a certain piece of data on this page. Now I can query it but I can’t delete it. What’s written wrong?

<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>
Copy after login
Copy after login

First, echo your delete sql and see if it is the result you want
Then go to the database to execute it and see if there is any effect.
Then there are still problems, we are troubleshooting

$cm is written like this '{$cm}'

There is no input field in your deletion, so there is no value submitted to the form, so nothing is deleted

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!