Mam taki problem:
Mam już gotową stronkę będącą namiastką internetowej bazy studentów. Mając już prawie wszystko gotowe trafiłem na problem nie do przeskoczenia: otoz chce, aby można było usuwać całe rekordy za pomocą checkbox'ów, Na internecie znalazłem sporo porad na ten temat, niestety nic mi nie dzała. Zamieszczam kod i bardzo proszę o pomoc, z góry piękne dzięki.
CODE
<html>
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Internetowa baza studentow</title> </head>
<body bgcolor="#FFC0A0">
<?php
try {
$dbh = new PDO('sqlite:./student.db');
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
echo '<h2>Lista studentow:</h2>';
echo '<table border="1" bordercolor="black" bgcolor="#FFFFD0">
<tr>
<td><b><center>ID</center></b></td>
<td><b><center>Imie</center></b></td>
<td><b><center>Nazwisko</center></b></td>
<td><b><center>Numer albumu</center></b></td>
<td><b><center>Zdjecie</center></b></td>
<td><b><center>Usun</center></b></td>
<td><b><center>Oceny</center></b></td>
</tr>';
foreach($dbh->query('SELECT id, imie, nazwisko, nr_albumu, zdjecie FROM student ORDER BY id') as $row) {
echo '<tr>
<td>'.$row["id"].'</td>
<td>'.$row["imie"].'</td>
<td>'.$row["nazwisko"].'</td>
<td>'.$row["nr_albumu"].'</td>
<td><center><img src="'.$row["zdjecie"].'" width="50" height="50"></center></td>';
// Poczatek problemu
echo '<td><center><form action="" method="post"><input type="checkbox" name="check[]" value="'.$row['id'].'"></form></center></td>';
// Koniec problemu
echo '<td><center><form action="oceny.php?id='.$row['id'].'" method="post"><input type="submit" value="Pokaz oceny"></form></center></td>
</tr>';
}
echo '</table><br/>';
echo '<form action="" method="post"><input type="submit" value="Usun zaznaczonych" name="usunz"></form><br/>';
if(isset($_POST["usunz"])) {
// Poczatek problemu
while($_POST["check"]) {
$dbh->exec('DELETE FROM student WHERE id = '.$_POST['check']);
}
// Koniec problemu
}
echo '<form action="dodaj.php"><input type="submit" value="Dodaj nowego studenta"></form>';
echo '<form action="sprawdz.php"><input type="submit" value="Sprawdz login i haslo"></form>';
?>
</body>
</html>
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Internetowa baza studentow</title> </head>
<body bgcolor="#FFC0A0">
<?php
try {
$dbh = new PDO('sqlite:./student.db');
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
echo '<h2>Lista studentow:</h2>';
echo '<table border="1" bordercolor="black" bgcolor="#FFFFD0">
<tr>
<td><b><center>ID</center></b></td>
<td><b><center>Imie</center></b></td>
<td><b><center>Nazwisko</center></b></td>
<td><b><center>Numer albumu</center></b></td>
<td><b><center>Zdjecie</center></b></td>
<td><b><center>Usun</center></b></td>
<td><b><center>Oceny</center></b></td>
</tr>';
foreach($dbh->query('SELECT id, imie, nazwisko, nr_albumu, zdjecie FROM student ORDER BY id') as $row) {
echo '<tr>
<td>'.$row["id"].'</td>
<td>'.$row["imie"].'</td>
<td>'.$row["nazwisko"].'</td>
<td>'.$row["nr_albumu"].'</td>
<td><center><img src="'.$row["zdjecie"].'" width="50" height="50"></center></td>';
// Poczatek problemu
echo '<td><center><form action="" method="post"><input type="checkbox" name="check[]" value="'.$row['id'].'"></form></center></td>';
// Koniec problemu
echo '<td><center><form action="oceny.php?id='.$row['id'].'" method="post"><input type="submit" value="Pokaz oceny"></form></center></td>
</tr>';
}
echo '</table><br/>';
echo '<form action="" method="post"><input type="submit" value="Usun zaznaczonych" name="usunz"></form><br/>';
if(isset($_POST["usunz"])) {
// Poczatek problemu
while($_POST["check"]) {
$dbh->exec('DELETE FROM student WHERE id = '.$_POST['check']);
}
// Koniec problemu
}
echo '<form action="dodaj.php"><input type="submit" value="Dodaj nowego studenta"></form>';
echo '<form action="sprawdz.php"><input type="submit" value="Sprawdz login i haslo"></form>';
?>
</body>
</html>