0
I’m having trouble at a crud in php and myqsl. My code doesn’t seem to be getting the id to perform the actions. The site has an administrative part in which I view registered users and can edit, delete and detail about each user.
Here is the code of list, it is associated with an html (users.html). No users.html I take php via javascript - I explain why I do this: I want to use php only to perform actions not to display actions, I want it to be behind actions. In the list I have 3 buttons that will perform such actions. Only he does not take the id to do.
<?php
// exibir error
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);
include 'conecta.php';
// monta a query
$sql = "SELECT id_user, usuario, nome, sobrenome FROM usuario";
// executa a query
$result = $conn->query($sql);
if ($result) {
while ($aux_query = $result->fetch_assoc())
{ ?>
<!-- Modal de Delete-->
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Deseja realmente excluir este usuário?
</div>
<div class="modal-footer">
<a id="confirm" class="btn btn-primary" href="excluir_user.php?edit=<?php echo $row['id_user']; ?>">Sim</a>
<a id="cancel" class="btn btn-default" data-dismiss="modal">Não</a>
</div>
</div>
</div>
</div> <!-- /.modal -->
<tr>
<th>
<div class="media align-items-center">
<a href="#" class="avatar rounded-circle mr-3">
<img alt="Image placeholder" src="../assets/img/theme/perfil1.jpg">
</a>
<div class="media-body">
<input type="hidden"><?php echo'' .$aux_query["id_user"]; ?></input>
<span class="mb-0 text-sm"><?php echo'' .$aux_query["usuario"]; ?></span>
</div>
</div>
</th>
<th>
<div class="media align-items-center">
<div class="media-body">
<span class="mb-0 text-sm"><?php echo '' .$aux_query["nome"]; ?></span>
</div>
</div>
</th>
<th>
<div class="media align-items-center">
<div class="media-body">
<span class="mb-0 text-sm"><?php echo '' .$aux_query["sobrenome"]; ?></span>
</div>
</div>
</th>
<td class="text-right">
<div class="dropdown">
<a class="btn btn-sm btn-icon-only text-light" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v"></i>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
<a href="detalhar_user.html?id= <?php echo ''.$aux_query["id_user"];?>" class="dropdown-item" >Detalhes</a>
<a href="atualizar_user.html?id=<?php echo ''.$aux_query["id_user"];?>" >Editar</a>
<button class="dropdown-item" data-toggle="modal" data-target="#delete-modal">Excluir</button>
</div>
</div>
</td>
</tr> <?php
}
$result->free();
} else {
echo "Erro: " . $sql . "<br>" . $conn->error;
}
// fecha ponto de conexão
$conn->close();
?>
UPDATE 1:
Here is the code of exclui_user.php and gives error on line 11 ($id = $_POST["id_user"];)
<?php
// exibir error ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);
include 'conecta.php';
$id = $_POST["id_user"];
// monta a query
$sql = "DELETE FROM usuario WHERE id_user = '$id'";
// executa a query
$result = $conn->query($sql);
if ($result) {
echo "Usuario excluído!";
} else {
echo "Erro: " . $sql . "<br>" . $conn->error;
}
// fecha ponto de conexão
$conn->close();
?>
Here is the code of exclui_user.php and gives error on line 11 ($id = $_POST["id_user"];) <? php

// exibir error
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);


include 'conecta.php';

$id = $_POST["id_user"];

// monta a query
$sql = "DELETE FROM usuario WHERE id_user = '$id'"; // executes the query $result = $Conn->query($sql); if ($result) { echo "Deleted user!" ; } Else { echo "Error: ". $sql . " <br>" . $Conn->error; } // closes connection point $Conn->close(); ;?>
– amandacostam9
If possible click on [Edit] and put the new code. In the comments it gets disorganized. Ps.: In the question you can press Ctrl + K to format it.
– Valdeir Psr