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 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题