dtsc14683 2019-05-26 22:01
浏览 67
已采纳

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

I have three files connecting to each other, my issue is that my delete function does not seem to be working. I'd like to know what is missing in my "public function Delete_Lease($db) {" the codes are shown are shown below. Basically, I use a for each to display a table, the edit works with no problem but the delete just stays on the same page and has no effect.

Table Name: for_lease

Values: leaseid, lease_type, lease_name, lease_address, lease_price, lease_condition, lease_description, featured_photo, createddate

table 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 } ?>

for_lease.vc.php

<?php
  $routePath = "../";

  require_once($routePath . "_config/db.php");
    $dbConfig = new config_db();
    $db = $dbConfig->init();

  require_once($routePath . "_mc/Property.mc.php");

  $mcProperty = new Property_MC();

  $lstProperty = $mcProperty->SelectObj_ByLeaseId($db);

  if (isset($_GET['delete'])){
    $rowProperty = $mcProperty->Delete_Lease($db);
  }
?>

Property.mc.php

<?php
Class Property_MC {

  public function SelectObj_ByLeaseId($db) {
  $stmt = $db->prepare(
    " SELECT leaseid, lease_type, lease_name, lease_address, lease_price, lease_condition, lease_description, createddate
      FROM for_lease"
  );

  $stmt->execute();
  $row = $stmt->fetchAll(PDO::FETCH_ASSOC);

  return $row;
  }

  public function Delete_Lease($db) {
  $stmt = $db->prepare(
    " DELETE * FROM
        for_lease
      WHERE
        leaseid = :leaseid "
  );
  }

} ?>
  • 写回答

2条回答 默认 最新

  • druzuz321103 2019-05-26 22:08
    关注

    Delete_Lease is missing binding and execution as well as what lease id to delete. the sql for delete does not need the "*".

    Property.mc.php

    public function Delete_Lease($db, $leaseid) {
        $stmt = $db->prepare(
            "DELETE FROM
            for_lease
            WHERE
            leaseid = :leaseid "
            );  
        $stmt->execute(['leaseid' => $leaseid]);
    }
    

    for_lease.vc.php

    if (isset($_GET['delete'])){
        $rowProperty = $mcProperty->Delete_Lease($db, $_GET['leaseid']);
    }
    

    fix delete button that overwrites delete id in for_lease.php

    <td>
        <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?