Beste medetweakers,
Voor een project op school is het de bedoeling dat je enkele en meerdere checkboxen kunt selecteren en verwijderen. Het probleem is dat het mij niet lukt!, heb al heel wat tutorials afgezocht op internet.
Hier mijn code:
<?php
$result = mysql_query("SELECT * from evenement") or die(mysql_error());
$count=mysql_num_rows($result);
?>
<table class="eventlijst">
<form method ="POST" ACTION="">
<tr>
<td>Naam</td><td><input type="text" size="8" name="naam"></td>
<td>Datum</td><td><input type="text" size="5" name="van"></td>
<td>tot</td><td><input type="text" size="5" name="tot"></td>
<td>Vereniging</td><td><select name="vereniging"><option value="%" selected></option><option value="1">De Blauwe Schuit</option><option value="2">De Deurdrievers</option><option value="3">De Deurzetters</option><option value="4">De Duumkes</option><option value="5">De Duvelse Dertien</option></select></td>
<td>Categorie</td><td><select name="categorie"><option value="%" selected></option><option value="1">Bierfeest</option><option value="2">Muziekfeest</option><option value="3">Themafeest</option></select></td>
<td> </td><td><input type="submit" name="Zoek" value="Zoek"></td> </form>
</table>
<br />
<form method="POST"<INPUT TYPE="submit" name="toevoegen" VALUE="toevoegen"> </form>
<form method="POST"> <input name="delete" type="submit" value="Delete"> <br /><br />
<table>
<tr class="thead">
<td width="10" class="thead"> </td><td width="75" class="thead">Naam</td><td width="125" class="thead">Begindatum</td><td width="125" class="thead">Einddatum</td><td width="100" class="thead">Vereniging</td><td width="100" class="thead">Categorie</td><td width="100" class="thead">Aanmelden?</td>
</table>
<?php
while($rows=mysql_fetch_array($result)){
?>
<table>
<tr>
<td width="15"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['evenementid']; ?>"></td>
<td width="85"><? echo $rows['naam']; ?></td>
<td width="130"><? echo $rows['begindatum']; ?></td>
<td width="175"><? echo $rows['einddatum']; ?></td>
<td width="100"><? echo $rows['categorieid']; ?></td>
<td width="100"><? echo $rows['organiserendeVerenigingid']; ?></td>
<td width="100"><? echo $rows['isAanmeldingVerplicht']; ?></td>
</tr>
</table>
</form>
<?php
}
?>
<?php
if(empty($_POST['delete']) || !is_numeric($_POST['delete']))
{
echo "Geen berichten geselecteerd";
} else {
foreach ($_POST['checkbox'] as $id)
{
mysql_query("DELETE FROM evenement WHERE evenementid='".$id."'") or die(mysql_error());
}
}
?>
Hoop dat jullie me kunnen helpen!
Alvast bedankt!
Voor een project op school is het de bedoeling dat je enkele en meerdere checkboxen kunt selecteren en verwijderen. Het probleem is dat het mij niet lukt!, heb al heel wat tutorials afgezocht op internet.
Hier mijn code:
<?php
$result = mysql_query("SELECT * from evenement") or die(mysql_error());
$count=mysql_num_rows($result);
?>
<table class="eventlijst">
<form method ="POST" ACTION="">
<tr>
<td>Naam</td><td><input type="text" size="8" name="naam"></td>
<td>Datum</td><td><input type="text" size="5" name="van"></td>
<td>tot</td><td><input type="text" size="5" name="tot"></td>
<td>Vereniging</td><td><select name="vereniging"><option value="%" selected></option><option value="1">De Blauwe Schuit</option><option value="2">De Deurdrievers</option><option value="3">De Deurzetters</option><option value="4">De Duumkes</option><option value="5">De Duvelse Dertien</option></select></td>
<td>Categorie</td><td><select name="categorie"><option value="%" selected></option><option value="1">Bierfeest</option><option value="2">Muziekfeest</option><option value="3">Themafeest</option></select></td>
<td> </td><td><input type="submit" name="Zoek" value="Zoek"></td> </form>
</table>
<br />
<form method="POST"<INPUT TYPE="submit" name="toevoegen" VALUE="toevoegen"> </form>
<form method="POST"> <input name="delete" type="submit" value="Delete"> <br /><br />
<table>
<tr class="thead">
<td width="10" class="thead"> </td><td width="75" class="thead">Naam</td><td width="125" class="thead">Begindatum</td><td width="125" class="thead">Einddatum</td><td width="100" class="thead">Vereniging</td><td width="100" class="thead">Categorie</td><td width="100" class="thead">Aanmelden?</td>
</table>
<?php
while($rows=mysql_fetch_array($result)){
?>
<table>
<tr>
<td width="15"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['evenementid']; ?>"></td>
<td width="85"><? echo $rows['naam']; ?></td>
<td width="130"><? echo $rows['begindatum']; ?></td>
<td width="175"><? echo $rows['einddatum']; ?></td>
<td width="100"><? echo $rows['categorieid']; ?></td>
<td width="100"><? echo $rows['organiserendeVerenigingid']; ?></td>
<td width="100"><? echo $rows['isAanmeldingVerplicht']; ?></td>
</tr>
</table>
</form>
<?php
}
?>
<?php
if(empty($_POST['delete']) || !is_numeric($_POST['delete']))
{
echo "Geen berichten geselecteerd";
} else {
foreach ($_POST['checkbox'] as $id)
{
mysql_query("DELETE FROM evenement WHERE evenementid='".$id."'") or die(mysql_error());
}
}
?>
Hoop dat jullie me kunnen helpen!
Alvast bedankt!