non funzionerà mai perchè in questo modo non fai altro che attribuire a tutti gli utenti una checkbox con lo stesso nome, invece ognuno deve avere una checkbox che lo identifichi.
Puoi benissimo, dopo aver la select che va a prendere tutti gli utenti del db, associare nome e numero ciclo ad ogni checkbox, cosi da poter renderle univoche per ogni utente.
es.
Codice PHP:
<?php
$db_host="localhost";
$db_name="XXX";
$db_user="XXX";
$db_password="";
mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
mysql_select_db($db_name) or die("errore database");
$sql = "SELECT * FROM utenti ORDER BY nome";
$result = mysql_query($sql);
?>
<form action="cancella.php" method="post" name="form_delete">
<table border="1">
<tr>
<th>ID</th>
<th>Nome</th>
<th>Cognome</th>
<th>Indirizzo</th>
<th>Cap</th>
<th>Citta</th>
<th>Telefono</th>
<th>Email</th>
<th>Nato</th>
<th>Cancella</th>
</tr>
<?php
$count = mysql_num_rows($result);
for ($i=0; $i<$count; $i++){
$row = mysql_fetch_array($result);
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['nome']; ?></td>
<td><?php echo $row['cognome']; ?></td>
<td><?php echo $row['indirizzo']; ?></td>
<td><?php echo $row['cap']; ?></td>
<td><?php echo $row['citta']; ?></td>
<td><?php echo $row['telefono']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['nato']; ?></td>
<td style="text-align:center;"><input type="checkbox" name="cancella_<?php echo $i;?>" value="<?php echo $row['id']; ?>"></td>
</tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="text-align:center;"><input type="hidden" name="totale" value="<?php echo $count; ?>"><input type="submit" value="Cancella"></td>
</table>
</form>
<?php
mysql_close();
?>
Infine nella pagina di destinazione(cancella.php), metterai uno script cosi
Codice PHP:
<?php
$db_host="localhost";
$db_name="XXX";
$db_user="XXX";
$db_password="";
mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
mysql_select_db($db_name) or die("errore database");
$totale = $_POST['totale'];
for ($i=0; $i<$totale; $i++){
if (!empty($_POST['cancella'.$i])){
$delete = "delete from utenti where id = ".$_POST['cancella'.$i];
mysql_query($delete);
}
}
?>