有人可以告诉我这里我做错了什么吗?我创建了一个表,每行都有一个删除按钮,当单击时会弹出一个模态并询问我是否要删除该行。但是当我点击按钮时没有任何反应。为什么会发生这种情况?(我怀疑这可能是因为INNER JOIN
)任何想法如何解决这个问题?
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> 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> Apagar</a>
<?php include('modal_delete.php'); ?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
模态(引导):
<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">×</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");
}?>
我是新手,所以如果出现问题,请帮助我。
答案 0 :(得分:2)
您不能使用GET执行删除请求,创建表单而不是锚点,并在其中放置一个按钮。使用post方法提出您的请求
答案 1 :(得分:1)
更改此行:
$query= "DELETE FROM book WHERE id_book = $id";
以强>
$query= "DELETE FROM book WHERE id_book = ".$id;