对于我的学校,我必须制作一个脚本,我可以在其中添加,编辑和删除数据库中的记录!
现在我忙于删除部分,但它不会工作..我尝试使用带有用户ID号的复选框删除记录。
它一直说工作成功但从不删除任何东西...... - , -
// // delete.php
<?php include "connect.php" ?>
<!DOCTYPE html>
<html>
<head>
<title>Verweider gebruiker</title>
</head>
<body>
<?php
$q="SELECT * FROM naw";
$result = mysqli_query($server,$q) or die(mysqli_error($server));
while ($r = mysqli_fetch_array($result)) {
?>
<form action="delete_user.php" method="POST">
<table>
<tr>
<td>
<td>
<input type="checkbox" name="id[]" value="<?php echo $r[0] ?>" />
</td>
<td>
<?php echo $r[1] ?>
</td>
<td>
<?php echo $r[2] ?>
</td>
<td>
<?php echo $r[3] ?>
</td>
<td>
<button>Verweider user(s)</button>
</td>
</td>
</tr>
</table>
</form>
<?php
}
mysqli_close($server);
?>
</body>
</html>
// // delete_user.php
<?php
include "connect.php";
error_reporting(E_ALL);
$chk = $_POST['id'];
$chkcount = count($chk);
if(!isset($chk))
{
?>
<script>
alert('Je moet minimaal 1 bericht selecteren');
window.location.href = 'delete.php';
</script>
<?php
}
else
{
for($i=0; $i<$chkcount; $i++)
{
$del = $chk[$i];
$q="DELETE FROM naw WHERE id=".$del;
}
if($q)
{
?>
// this alert i get everytime, but it didn't delete anything... i don't get it :(
<script>
alert('De gebruiker is verwijderd');
window.location.href='gebruiker.php';
</script>
<?php
}
else
{
?>
<script>
alert('Er ging iets fout, probeer het opnieuw');
window.location.href='delete.php';
</script>
<?php
}
}
?>