0
Hello, I would like to make a sweetalert to delete the records of my site, but do not know how to do because I do not understand javascript... Someone can give me a light ?
My class/crud.php page where the querys are (the delete part):
public function excluirAluno($idAluno){
global $pdo;
$sql = $pdo->prepare("DELETE FROM alunos WHERE id_alunos = '$idAluno'");
$sql->execute();
}
public function excluirPagamentos($idAluno){
global $pdo;
$sql = $pdo->prepare("DELETE FROM pagamentos WHERE alunos_id = '$idAluno'");
$sql->execute();
}
And here comes home.php where they show the records (only php code):
<?php
include_once 'config.php';
global $pdo;
$sql = "select * from alunos left join pagamentos on id_alunos =
pagamentos.alunos_id order by nome";
$sql = $pdo->query($sql);
if ($sql->rowCount() > 0)
{
foreach ($sql->fetchAll() as $aluno):
?>
<tr>
<td> <?php echo $aluno['nome']; ?> </td>
<td> <?php echo $aluno['fone']; ?> </td>
<td> <?php echo $aluno['email']; ?> </td>
<td> <?php echo $aluno['situacao_aluno']; ?>
</td>
<?php
echo "<td><a href='editar.php?id_alunos=" . $aluno['id_alunos'] . "'
class='btn btn-dark' role='button'>Editar</a></td>";
echo "<td><a href='delete_submit.php?id_alunos=" . $aluno['id_alunos'] . "'
class='btn btn-danger'>Deletar</a></td>";
echo "</tr>";
?>
</tr>
<?php
endforeach;
}
?>
Hello, look for the confirm dialog part in the documentation, I think it might be useful in your case. https:/sweetalert2.github.io/#examples
– renanvm
@renanzin thanks!!! I found the example.... only now I don’t know where to apply it in my code...I believe it is in my home.php where has the delete button, but then sweetalert code enters my php code ?
– Verônica Emschermann
Here’s how to include a Javascript code on your page, after that, you can enter the Sweet Alert code and elaborate your logic for deletion.. http://tableless.github.io/iniciantes/manual/js/inserindo-js.html
– renanvm
Thank you @re!!!!!!
– Verônica Emschermann