-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
38 lines (29 loc) · 895 Bytes
/
delete.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
include('dbcon.php');
function deleteStudentById($connection, $id) {
$query = "DELETE FROM alunos WHERE id = ?";
$stmt = mysqli_prepare($connection, $query);
if (!$stmt) {
die("Falha na preparação: " . mysqli_error($connection));
}
mysqli_stmt_bind_param($stmt, "i", $id);
$success = mysqli_stmt_execute($stmt);
if (!$success) {
die("Deu ruim: " . mysqli_error($connection));
}
mysqli_stmt_close($stmt);
return $success;
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
if (filter_var($id, FILTER_VALIDATE_INT) === false) {
die("ID inválido");
}
$wasDeleted = deleteStudentById($connection, $id);
if ($wasDeleted) {
header('location:index.php?delete_msg=Registro removido da base de dados!');
} else {
die("Erro ao deletar o registro");
}
}
?>