I have a HTML table generated from PHP (from the results of SQL query):
echo "<table border=\"5\"><tr><th>Codice</th><th>Titolo</th><th>Anno Creazione</th><th>Materiale</th><th>Altezza</th><th>Peso</th><th>Museo</th></tr>";
while($row = mysqli_fetch_assoc($results)) {
echo "<tr><td>".$row["Codice"]."</td><td>".$row["Titolo"]."</td><td>".$row["Anno_creazione"]."</td><td>".$row["Materiale"]."</td><td>".$row["Altezza"]."</td><td>".$row["Peso"]."</td><td>".$row["Museo"]."</td><td><button id=\"modifica\" type=\"button\">Modifica</button></td><td><button id=\"cancella\" type=\"button\">Cancella</button></td></tr>";
}
echo "</table>";
Then, I have this JQuery:
$("#cancella").click(function(){
if(confirm("Vuoi davvero eliminare questi dati?")){
var codice = <?php echo json_encode($cod); ?>;
var tipo = <?php echo json_encode($tipo_opera); ?>;
window.location.href = "delete.php?codice="+codice+"&tipo="+tipo;
}
});
This click function works only for the "delete" button at the first row. Why?