duanaozhong0696 2019-05-15 14:43
浏览 94
已采纳

弹出确认删除PHP

So my code is below which read from dmgeqdelete.php that will instantly delete data from database. <td align="center"> <a href="dmgeqdelete.php?damagedID=<?php echo $row["damagedID"]; ?>" >Delete</a> </td>

Im trying to add a pop up confirmation for above code. i have tried <td align="center"> <a href="dmgeqdelete.php?damagedID=<?php echo $row["damagedID"]; ?>" onclick="return confirm('Are you sure?')">Delete</a> </td> end up with no action happen

dmgeqdelete.php

<?php
include('dbConfig.php');
$damagedID=$_REQUEST['damagedID'];
$query = "DELETE FROM damagedeq WHERE damagedID=$damagedID"; 
$result = mysqli_query($conn,$query) or die ( mysqli_error());
header("Location: dmgeqview.php"); 
?>

full code

<?php
include('dbConfig.php');
?>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>View Damaged Equipment Records</title>
  <link rel="stylesheet" href="css/style.css" />
</head>

<body>
  <div class="form">
    <p><a href="report.php">Home</a> | <a href="index.php">Logout</a></p>
    <h2>View Records</h2>
    <table width="100%" border="1" style="border-collapse:collapse;">
      <thead>
        <tr>
          <th><strong>No</strong></th>
          <th><strong>Damage ID's</strong></th>
          <th><strong>EQ ID's</strong></th>
          <th><strong>Student ID's</strong></th>
          <th><strong>Staff ID's</strong></th>
          <th><strong>Date reported</strong></th>
          <th><strong>Date repaired</strong></th>
          <th><strong>Equipment Status</strong></th>
        </tr>
      </thead>
      <tbody>
        <?php
$count=1;
$sel_query="Select * from damagedeq ORDER BY damagedID desc;";
$result = mysqli_query($conn,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
          <tr>
            <td align="center">
              <?php echo $count; ?>
            </td>
            <td align="center">
              <?php echo $row["damagedID"]; ?>
            </td>
            <td align="center">
              <?php echo $row["equipmentID"]; ?>
            </td>
            <td align="center">
              <?php echo $row["studentID"]; ?>
            </td>
            <td align="center">
              <?php echo $row["staffID"]; ?>
            </td>
            <td align="center">
              <?php echo $row["dateReported"]; ?>
            </td>
            <td align="center">
              <?php echo $row["dateRepaired"]; ?>
            </td>
            <td align="center">
              <?php echo $row["equipmentStatus"]; ?>
            </td>
            <td align="center">
              <a href="dmgequp.php?damagedID=<?php echo $row[" damagedID "]; ?>">Edit</a>
            </td>
            <td align="center">
              <a href="dmgeqdelete.php?damagedID=<?php echo $row[" damagedID "]; ?>">Delete</a>
            </td>
          </tr>
          <?php $count++; } ?>
      </tbody>
    </table>
  </div>
</body>

</html>

</div>
  • 写回答

1条回答 默认 最新

  • doulangdang9986 2019-05-15 14:55
    关注

    Here you just need to stop the further execution of the code

    onclick="return confirm('Are you sure?')"
    

    adding the return false at the end like this

    onclick="return confirm('Are you sure?'); return false;"
    

    When clicking on cancel nothing will happen, but if click on ok it will go to link
    Here is a full code snippet

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>View Damaged Equipment Records</title>
      <link rel="stylesheet" href="css/style.css" />
    </head>
    
    <body>
      <div class="form">
        <p><a href="report.php">Home</a> | <a href="index.php">Logout</a></p>
        <h2>View Records</h2>
        <table width="100%" border="1" style="border-collapse:collapse;">
          <thead>
            <tr>
              <th><strong>No</strong></th>
              <th><strong>Damage ID's</strong></th>
              <th><strong>EQ ID's</strong></th>
              <th><strong>Student ID's</strong></th>
              <th><strong>Staff ID's</strong></th>
              <th><strong>Date reported</strong></th>
              <th><strong>Date repaired</strong></th>
              <th><strong>Equipment Status</strong></th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="center">000</td>
              <td align="center">111</td>
              <td align="center">222</td>
              <td align="center">333</td>
              <td align="center">444</td>
              <td align="center">555</td>
              <td align="center">666</td>
              <td align="center">777</td>
              <td align="center">
                <a href="dmgequp.php?damagedID=aaa">Edit</a>
              </td>
              <td align="center">
                <a href="dmgeqdelete.php?damagedID=bbb" onclick="return confirm('Are you sure?'); return false;">Delete</a>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </body>
    
    </html>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 qgcomp混合物线性模型分析的代码出现错误:Model aliasing occurred
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'