SQL 删除功能在表中不起作用

我有三个相互连接的文件,我的问题是我的删除功能似乎不起作用。我想知道我的“公共函数 Delete_Lease($db) {”中缺少什么,代码如下所示。基本上,我使用一个 for each 来显示一个表格,编辑没有问题,但删除只是停留在同一页面上并且没有任何效果。

表名: for_lease

值: leaseid、lease_type、lease_name、lease_address、lease_price、lease_condition、lease_description、featured_photo、createddate

http://img.mukewang.com/60e818820001283416000408.jpg

for_lease.php


<?php

  session_start();

  require_once('for_lease.vc.php');

?>


 <?php foreach($lstProperty as $rowProperty) { ?>

       <tr align="center">

         <td>

          <a href="for_lease_edit.php?i=<?php echo($rowProperty['leaseid']); ?>"><input type="submit" class="btn bg-color-blue color-white form-control" name="edit" value="EDIT"></a>

         </td>


         <td>

           <?php

             echo($rowProperty['lease_name']);

           ?>

         </td>


         <td>

           <?php

             echo($rowProperty['lease_address']);

           ?>

         </td>


         <td>

           <?php

             echo($rowProperty['lease_type']);

           ?>

         </td>


         <td>

           <?php

             echo 'PHP'.' '.number_format(($rowProperty['lease_price']));

           ?>

         </td>


         <td>

           <?php

             echo($rowProperty['lease_condition']);

           ?>

         </td>


         <td>

           <?php

             echo( date("Y-m-d", strtotime($rowProperty['createddate']) ));

           ?>

         </td>


         <td>

           <a href="for_lease.php?delete=<?php echo($rowProperty['leaseid']); ?>" onclick="return confirm('Are you sure?');"><input type="submit" class="btn bg-color-red color-white form-control" name="delete" value="DELETE"></a>

         </td>

       </tr>

 <?php } ?>


蝴蝶不菲
浏览 256回答 2
2回答

千巷猫影

Delete_Lease 缺少绑定和执行以及要删除的租约 ID。用于删除的 sql 不需要“*”。属性.mc.phppublic function Delete_Lease($db, $leaseid) {&nbsp; &nbsp; $stmt = $db->prepare(&nbsp; &nbsp; &nbsp; &nbsp; "DELETE FROM&nbsp; &nbsp; &nbsp; &nbsp; for_lease&nbsp; &nbsp; &nbsp; &nbsp; WHERE&nbsp; &nbsp; &nbsp; &nbsp; leaseid = :leaseid "&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp;&nbsp;&nbsp; &nbsp; $stmt->execute(['leaseid' => $leaseid]);}for_lease.vc.phpif (isset($_GET['delete'])){&nbsp; &nbsp; $rowProperty = $mcProperty->Delete_Lease($db, $_GET['leaseid']);}修复覆盖 for_lease.php 中删除 ID 的删除按钮<td>&nbsp; &nbsp; <a href="for_lease.php?leaseid=<?php echo($rowProperty['leaseid']); ?>" onclick="return confirm('Are you sure?');"><input type="submit" class="btn bg-color-red color-white form-control" name="delete" value="DELETE"></a></td>

湖上湖

你不是在执行 sql 语句,你只是在准备它。此外,您的代码设置方式,您需要将 传递leaseid给您的删除功能。试试这个。for_lease.vc.php<?php&nbsp; $routePath = "../";&nbsp; require_once($routePath . "_config/db.php");&nbsp; &nbsp; $dbConfig = new config_db();&nbsp; &nbsp; $db = $dbConfig->init();&nbsp; require_once($routePath . "_mc/Property.mc.php");&nbsp; $mcProperty = new Property_MC();&nbsp; $lstProperty = $mcProperty->SelectObj_ByLeaseId($db);&nbsp; if (isset($_GET['delete'])){&nbsp; &nbsp; $rowProperty = $mcProperty->Delete_Lease($db, $_GET['delete']);&nbsp; }?>属性.mc.php&nbsp;public function Delete_Lease($db, $leaseid) {&nbsp; $stmt = $db->prepare(&nbsp; &nbsp; " DELETE FROM&nbsp; &nbsp; &nbsp; &nbsp; for_lease&nbsp; &nbsp; &nbsp; WHERE&nbsp; &nbsp; &nbsp; &nbsp; leaseid = :leaseid "&nbsp; );&nbsp; $stmt->execute([':leaseid' => $leaseid]);&nbsp;&nbsp;&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP