当我按下第一行的DELETE或EDIT按钮时,它们就会工作,链接从http://localhost/index.php更改为http://localhost/modif.php?id=1(用于编辑)或http://localhost/supp.php?id=1(用于删除),按钮就会工作。 但是当我在任何其他行上按下DELETE或EDIT按钮时,它不会将我重定向到另一个页面(这些按钮不起作用),在这两个按钮的情况下,链接这次从http://localhost/index.php更改为http://localhost/supp3.php。
index.php代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Index</title>
</head>
<body>
<table border="1" align="center">
<caption><b><h1>La liste des étudiants</h1></b></caption>
<tr><td align="center"><b>Matricule</td><td align="center"><b>Nom</td><td align="center"><b>Prénom</td><td align="center"><b>Adresse</td><td align="center"><b>Date de Naissance</td><td align="center"><b>E-mail</td>
<td align="center"><b>Password</td><td align="center" colspan="3"><b>Action</td></tr>
<?php
include 'connect.php';
$sql = "SELECT * FROM etudiant";
$res = mysqli_query($connect, $sql);
if (mysqli_num_rows($res)>0){
while($row = mysqli_fetch_assoc($res))
{
echo "<tr><td align='center'>".$row['matricule']."</td>";
echo "<td align='center'>".$row['nom']."</td>";
echo "<td align='center'>".$row['prenom']."</td>";
echo "<td align='center'>".$row['adresse']."</td>";
echo "<td align='center'>".$row['date_naissance']."</td>";
echo "<td align='center'>".$row['email']."</td>";
echo "<td align='center'>".$row['password']."</td>";
echo "<td><a href='Modif.php?id=".$row['id']."'><button>Edit</button></a>";
echo "<td><a href='Supp.php?id=".$row['id']."'><button>Delete</button></a></td>";
echo "<form method='post' action='Supp3.php'> <td align='center'> <input type='checkbox' name='sup[]' value='".$row['id']."'></td></tr>";
}
echo "<tr><td colspan='7'></td><td colspan='3' align='center'><button>Suppression multiple</button></td></tr></form>";
}
else
echo "<tr><td colspan ='8' align='center'>Pas de données disponibles.</td></tr>";
?>
</table>
<p align="center"><a href="Ajout1.php"><button>Ajouter un étudiant</button></a></p>
</body>
</html>
Supp3.PHP代码:
<?php
if(isset($_POST['sup']))
{
include 'connect.php';
$sup = $_POST['sup'];
foreach($sup as $key => $value){
$sql = "DELETE * FROM etudiant WHERE id= '$value'";
mysqli_query($connect, $sql);
}
}
include 'Index.php';
请尝试使用“。” 运算符将$value包含在查询中
$SQL=“从etudiant中删除*,其中id='$Value'”;