PHP用bootstrap,删除主题

时间:2016-03-22 15:56:14

标签: javascript php mysql

当我想从管理面板中删除某个主题时出现问题, 如果我单击删除按钮,显示一个模式,看你确定要删除吗? 问题如果我点击是代码删除其他主题:'( 这是我的代码:'(

<td><a href="#del" data-toggle="modal" class="btn btn-danger btn-xs navbar-btn">Delete</a>
</td>

</tr>

<div class="modal fade" id="del" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <p>Supprimer !</p>
      </div>
      <div class="modal-body">
        <p>Vous voulez vraiment supprimer ?</p>
      </div>
      <div class="modal-footer">
        <a class="btn btn-default" data-dismiss="modal">Non</a>
        <a href="projetslist.php?del_pro='.$rows['idprojets'].'" class="btn btn-danger">Oui</a>
      </div>
    </div>
  </div>
</div>
';

代码PHP

if(isset($_GET['del_pro'])){
			$del = $_GET['del_pro'];
			$sql = "DELETE FROM projets WHERE idprojets = '$del' ";
			if($run = mysqli_query($conn,$sql)){
				$error = '<div class="alert alert-success">Vous avez supprimer la pub avec success</div>';
			}
		}

删除最后一个主题

3 个答案:

答案 0 :(得分:0)

您的代码片段

<a href="projetslist.php?delpro='.$rows['idprojets'].'" class="btn btn-danger">Oui</a>

        if(isset($_GET['del_pro'])){
            $del = $_GET['del_pro'];
            $sql = "DELETE FROM projets WHERE idprojets = '$del' ";
            if($run = mysqli_query($conn,$sql)){
                $error = '<div class="alert alert-success">Vous avez supprimer la pub avec success</div>';
            }
        }

如您所见,您有两个不同的变量:delpro和del_pro

您需要进行以下更改:

<a href="projetslist.php?del_pro='.$rows['idprojets'].'" class="btn btn-danger">Oui</a>

答案 1 :(得分:0)

你应该做这样的事情(我写的很快!可能有一些错误)并且不是功能代码,你必须编辑一些部分:

<table>
<!-- iterate with php the $projects object (or whatever the name is) -->
<?php foreach($projects as $row){ ?>
  <tr><!-- your td of the project... -->
     <td><a id="<?php $rows['idprojets']; ?>" href="#del" data-toggle="modal" class="btn btn-danger btn-xs navbar-btn">Delete</a></td>
  </tr>
<?php } ?>
</table>

<div class="modal fade" id="del" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <p>Supprimer !</p>
      </div>
      <div class="modal-body">
        <p>Vous voulez vraiment supprimer ?</p>
      </div>
      <div class="modal-footer">
        <a class="btn btn-default" data-dismiss="modal">Non</a>
        <a class="btn btn-danger delete_row">Oui</a>
      </div>
    </div>
  </div>
</div>

<script type='text/javascript'>
    $(document).ready(function(){
        $('.bdn-danger').click(function(e){
            e.preventDefault();
            var id = $(this).attr('id'); //get the id of the clicked 'a'
            $('.modal').modal(); //show the modal

            $('.delete_row').click(function(){
                var url = "projetslist.php?del_pro="+id; //pass the id throught get
                $.get(url, function(){ //doSomething; }); 
            });
        });
    });
</script>

然后在php部分:

$_GET['del_pro']

答案 2 :(得分:-1)

您的GET将转到delpro,但在您的PHP脚本中,您正在寻找del_pro