-3
I am having difficulty executing the deletion of a person in the Mysql database using ID, but it does not perform the deletion as the ID entered for deletion still remains in the database and does not show on the page in PHP.
<!DOCTYPE html>
<html>
<head>
<title> Excluir </title>
</head>
<body>
<form method="GET" action="excluir_cliente.php">
<p> Nome do ID: <input type="text" name="id_cliente" size=30> </p>
<p> <input type="submit" value="Eliminar"> </p>
<p> <a href="aluno.php"> Formulário aluno </a>
</form>
</body>
</html>
<html>
<head>
<title> Remover </title>
</head>
<body>
<h2> Remover cliente </h2>
<?php
$codrem = $_GET['id_cliente'];
if (!$codrem) {
echo 'Volte atrás e escreva o código do cliente a remover.';
}
echo "Cliente a remover: $codrem. <p>";
$ligax = mysqli_connect('localhost', 'root','');
if (!$ligax){
echo "<p> Falha na ligação."; exit;
}
mysqli_select_db($ligax, 'aluno');
$consulta = "SELECT * FROM cliente";
$result = mysqli_query($ligax, $consulta);
$nr_antes = mysqli_num_rows($result);
$remove = "DELETE FROM cliente WHERE id_cliente = '%$codrem%'";
$result = mysqli_query($ligax, $remove);
if ($result==0) echo "<p> Não removido <br>";
$consulta = "SELECT * FROM cliente";
$result = mysqli_query($ligax, $consulta);
$nr_depois = mysqli_num_rows($result);
$nr_removidos = $nr_antes - $nr_depois;
echo 'Nº de registos removidos: '.$nr_removidos;
?>
<p> <a href="listar.php"> Listar registos </a>
</body>
</html>
It didn’t work out and it’s showing off
Não removido
.– user141036
actually occurred to delete in the database, because looking at your delete this wrong place %
– MMello
Another thing q might be is its mysqli_query function, it is used for SELECT, SHOW, DESCRIBE or EXPLAIN and not for delete. You can replace it with mysqli_real_query($ligax, $remove), which will return TRUE and FALSE.
– MMello