1
I have this code:
<?php
if ($result = $mysqli->query("SELECT * FROM usuario ORDER BY id"))
{
if ($result->num_rows > 0)
{
echo "<table border='1' cellpadding='5' cellspacing=0 style=border-collapse: collapse bordercolor='#41c88c'>";
// definir cabeçalhos de tabela
echo "<tr> <th>ID</th> <th>Nome</th> <th>Email</th></tr>";
while ($row = $result->fetch_object())
{
// cria uma linha para cada registro
echo "<tr>";
echo "<td>" . $row->id . "</td>";
echo "<td>" . $row->nome . "</td>";
echo "<td>" . $row->email . "</td>";
echo "<td><a href='edit_usu.php?id=" . $row->id . "'>Editar</a></td>";
echo "<td><a href='delete.php?id=" . $row->id . "'>Deletar</a></td>";
echo "</tr>";
}
echo "</table>";
}
}
?>
and I need a text box to ask before if I really want to delete the data, what’s the best way to do that? grateful.
I tried to use it that way:
<script type="text/JavaScript">
function delete(){
var agree=confirm("deseja deletar os dados??");
if (agree)
return true ;
else
return false ;
}
</script>
but I don’t know how to use the variable $confirm
Ah, the name of your function is
delete
.delete
is a reserved word for Javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete. Changes function name (toremove
, for example) and everything should work.– gabrielhof
delete was just as an example, the variable I used was idlink and what I can’t understand is the syntax error that runs on this line echo "<td><a href='delete.php? id=" . $Row->id . " ' onclick="Return confirm('Are you sure you want to delete this record?');">Delete</a></td>";
– Thiago
I edited my answer. As @People mentioned, double quotes were missing because of
echo
.– gabrielhof