PHP 删除按钮...不起作用(模态)
PHP delete button... doesn't work(modal)
有人可以告诉我我做错了什么吗?我创建了一个 table ,它在每一行中都有一个删除按钮,单击时会弹出一个模式并询问我是否要删除该行。但是当我点击按钮时没有任何反应。为什么会这样?(我怀疑可能是因为 INNER JOIN
)如何解决这个问题?
list_book.php(内连接):
<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>
模态(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">×</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");
}?>
我是这方面的新手,所以如果有什么问题...请帮助我。
您不能使用 GET 执行删除请求,创建一个表单而不是锚点,并在其中放置一个按钮。使用 post 方法提出请求
When you should use get & post request
更改此行:
$query= "DELETE FROM book WHERE id_book = $id";
至
$query= "DELETE FROM book WHERE id_book = ".$id;
有人可以告诉我我做错了什么吗?我创建了一个 table ,它在每一行中都有一个删除按钮,单击时会弹出一个模式并询问我是否要删除该行。但是当我点击按钮时没有任何反应。为什么会这样?(我怀疑可能是因为 INNER JOIN
)如何解决这个问题?
list_book.php(内连接):
<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>
模态(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">×</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");
}?>
我是这方面的新手,所以如果有什么问题...请帮助我。
您不能使用 GET 执行删除请求,创建一个表单而不是锚点,并在其中放置一个按钮。使用 post 方法提出请求
When you should use get & post request
更改此行:
$query= "DELETE FROM book WHERE id_book = $id";
至
$query= "DELETE FROM book WHERE id_book = ".$id;