gpt4 book ai didi

php - 如何修复从 Bootstrap 中删除模式(仅删除第一行)

转载 作者:行者123 更新时间:2023-11-29 03:16:18 25 4
gpt4 key购买 nike

当我想删除一行时遇到问题,它只删除了第一行,我正在使用 php 和 bootstrap modal

ajout.php 这个页面是我用 id 调用 deleteEntreprise.php 的地方

$pdo = new PDO('mysql:dbname=test;host=localhost','root','root');

$pdoStat = $pdo->prepare('SELECT * FROM entreprise');

$ExecuteIsOk = $pdoStat->execute();

$entreprises = $pdoStat->fetchAll()


<?php foreach ($entreprises as $entreprise): ?>

<tbody>
<tr>
<td >
<?= $entreprise['id'] ?>
</td>
<td>
<a href="liste.php?id=<?= $entreprise['id'] ?>" style="text-decoration : none !important; color : white !important;"><?= $entreprise['nom'] ?></a>
</td>
<td>
<button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#exampleModal">Supprimer
</button>
</td>
</tbody>

</tr>


<div class="modal fade" id="exampleModal" tabindex="0" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">ATTENTION !</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Etes-vous sûr(e) de vouloir supprimer le compte ?
</div>
<div class="modal-footer">
<button type="button" class="btn-sm btn-secondary" data-dismiss="modal">Fermer</button>
<a href="deleteEntreprise.php?id=<?= $entreprise['id'] ?>" class="btn btn-danger btn-sm active" role="button" aria-pressed="true">Supprimer le compte</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</table>

deleteEntreprise.php 删除企业的sql查询

<?php

// Cette fonction permet de supprimer une fiche entreprise de la base données

$entreprise_id = $_GET['id'];

require 'inc/db.php';
$req = $pdo->prepare('SELECT * FROM entreprise WHERE id = ?');
$req->execute([$entreprise_id]);
$user = $req->fetch();
session_start();


$pdo->prepare('DELETE FROM entreprise WHERE id = ? ')->execute([$entreprise_id]);

$_SESSION['flash']['success'] = 'Lentreprise a bien été supprimer de la base de données.';
// $_SESSION['auth'] = $user;
header('Location: ajout.php');
exit();

我希望我已经提供了足够的信息来帮助解决我的问题。

如有任何帮助,我们将不胜感激!

谢谢,祝你有美好的一天!

最佳答案

试一试:

<table>
<tbody>

<?php foreach ($entreprises as $entreprise): ?>

<tr>
<td>
<?= $entreprise['id'] ?>
</td>
<td>
<a href="liste.php?id=<?= $entreprise['id'] ?>" style="text-decoration: none!important; color: white!important;"><?= $entreprise['nom'] ?></a>
</td>
<td>
<a href="#exampleModal<?= $entreprise['id'];?>" class="btn btn-sm btn-danger" data-toggle="modal">Supprimer</a>
</td>
</tr>

<div class="modal fade" id="exampleModal<?= $entreprise['id'];?>" tabindex="0" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">ATTENTION !</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Etes-vous sûr(e) de vouloir supprimer le compte ?
</div>
<div class="modal-footer">
<button type="button" class="btn-sm btn-secondary" data-dismiss="modal">Fermer</button>
<a href="deleteEntreprise.php?id=<?= $entreprise['id'] ?>" class="btn btn-danger btn-sm active" role="button" aria-pressed="true">Supprimer le compte</a>
</div>
</div>
</div>
</div>

<?php endforeach; ?>

</tbody>
</table>

关于php - 如何修复从 Bootstrap 中删除模式(仅删除第一行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55864988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com