Bootstrap模态删除确认

时间:2016-09-11 14:23:38

标签: php twitter-bootstrap bootstrap-modal

美好的一天!我的bootstrap模式中有一个问题,我想用模态删除帖子。

这是我的PHP代码,它切换了delete_modal.php

<?php
    if ($row['member_id'] == $_SESSION['member_id']){
    echo " 
     <div style='float:right;'>
       <a href='#<?php echo $id; ?>' data-toggle='modal' data-target='#myModal'>Delete</a>
     </div>";}

    else{
    echo "
      <div style='float:right;'>
        <a href='#'>Delete</a>
      </div>";
    }
?>

接下来是我的delete_modal.php

<div class="modal fade" id="myModal" role="dialog">
   <div class="modal-dialog">
     <!-- Modal content-->
     <div class="modal-content">

        <div class="modal-header">
           <button type="button" class="close" data-dismiss="modal">&times;</button>
           <h4 class="modal-title">Modal Header</h4>
        </div>

        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>

        <div class="modal-footer">
          <button  id="<?php echo $id; ?>" href="deleteposthome.php?id='.$row['post_id'].'" type="button" class="btn btn-danger" data-dismiss="modal">Delete</button>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>

     </div>                                       
   </div>
</div>

现在这是我的deleteposthome.php

    <?php
      require ("connection.php");  
    ?>  

    <?php
       $id =$_GET['id'];
      mysql_query("DELETE FROM posts WHERE post_id = '$id'")
      or die(mysql_error());    
    ?>

我不知道如何获取ID以便可以使用模态删除它!请帮帮我

1 个答案:

答案 0 :(得分:1)

这是我的回答,我已经问过这个问题多少个月了。

<div class='modal-footer' style='background-color:#1F4E78;'>
    <a class='btn btn-danger' href='deleteposthome.php?id=".$row['post_id']."'> Delete</a>
</div>