ds2128629 2015-04-26 14:08
浏览 21
已采纳

PHP删除按钮...不起作用(模态)

Can someone tell me what I'm doing wrong here? I create a table which has a delete button in each row, when clicked pops up an modal and asks if I want to delete the row. But when i click on the button nothing happens. Why is this happen?(I suspect it may be because of the INNER JOIN) Any ideas how to solve this?

list_book.php (INNER JOIN):

 <table class="table table-bordered table-hover" id="datatable">
    <thead>
        <tr> 
            <th>Número</th>
            <th>Estante</th>
            <th>Obra</th>
            <th>Autor</th>
            <th>Categoria</th>
            <th>Ano Escolaridade</th> 
            <th>Observação</th>
            <th class="text-center">Opções</th>
        </tr>
    </thead>
    <tbody> 
        <?php
        $query = "SELECT B.number, B.shelf, B.title, B.author, B.obs, C.category_name, S.scholarity_name FROM book AS B 
        INNER JOIN category AS C ON C.id_category=B.category_id INNER JOIN scholarity AS S ON S.id_scholarity=B.scholarity_id";
        $res = mysql_query($query);
        mysql_set_charset('utf-8');
        if (!$res) {
            echo "Erro ao executar a query";
        } else {
            while ($dados = mysql_fetch_array($res)) {
                ?>
                <tr>
                    <td><?php echo $dados['number']; ?></td>
                    <td><?php echo $dados['shelf']; ?></td>
                    <td><?php echo $dados['title']; ?></td>
                    <td><?php echo $dados['author']; ?></td>
                    <td><?php echo $dados['category_name']; ?></td>
                    <td><?php echo $dados['scholarity_name']; ?></td>
                    <td><?php echo $dados['obs']; ?></td>
                    <td class="text-center">
                        <a href="#" class="btn btn-warning btn-xs"><span class="fa fa-edit"></span>&nbsp;Editar</a>
                        <a class="btn btn-danger btn-xs" data-toggle="modal" data-target="#<?php echo $dados['id']; ?>" data-whatever="@mdo"><span class="fa fa-trash"></span>&nbsp;Apagar</a>
                        <?php include('modal_delete.php'); ?>
                    </td>
                </tr>
                <?php
            }
        }
        ?>
    </tbody>
</table>

MODAL(BOOTSTRAP):

<div class="modal"  id="<?php echo $dados['id_book']; ?>" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog">
     <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title text-left">Apagar</h4>
        </div>
        <div class="modal-body text-left">
            <p>Deseja apagar este  registro?</p>
        </div>
        <div class="modal-footer">
            <a href="../delete/delete_book.php?id=<?php echo $dados['id_book']; ?>" type="button" class="btn btn-primary">Apagar</a>
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
        </div>
    </div>
</div>

delete_book.php

<?php
session_start();
require("../../conexao/conexao.php");

$id = $_GET["id"];
$query= "DELETE FROM book WHERE id_book = $id";
$delete= mysql_query($query);
    if(!$delete){
        echo "Erro!! Não foi possivel apagar dado.";    
    }
    else{
        echo"Dado removido com sucesso!";
            header("Location: ../list/list_book.php");
    }?>

I'm new on this so if something's wrong... please help me.

  • 写回答

2条回答 默认 最新

  • dongliqian6245 2015-04-26 20:55
    关注

    You must not do your delete request with GET , Create a form instead of anchor , and place a button inside it. make your request with post method

    When you should use get & post request

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊