-1
I’m not getting an id to a modal window. Could help me?
I’m using a table, which lists all the names and CNPJ’s of registered customers.
I created a loop, to show in each row of the table, the change and delete buttons.
The change button works perfectly, but the delete button (which is calling the modal to confirm client deletion, is only taking the id of the first client from the table, and not the selected client).
Follow the page code with table and modal:
include ".. /connection.php";$command = "Select * from tbclient";
if (!Empty($pesq)) { $command .= " Where razao_social LIKE '%" . $pesq . " %' "; }elseif(!Empty($pesq2)){ $command .= " Where cnpj = $pesq2"; }
$command .= " order by razao_social";
$sql = mysqli_query($connect, $command);
?>
Customer Consultation
<div style="overflow: auto; width: 100%; height:480px; max-height: 480px;">
<table style="width: 80%; background-color: #fff" align="center" border="0">
<tr>
<th style="width: 50%; background-color: #2e4e8e; color: #fff;">
<form action='clienteconsulta.php' method="GET" >
Nome<br><br>
<input type="text" name='pesquisa' value='<?php echo $pesq ?>'style="height: 30px; color:#000;" >
</th>
<th style="background-color: #2e4e8e;color: #fff;">
CNPJ<br><br>
<input type="text" name='consultacnpj' value='<?php echo $pesq2 ?>' style="height: 30px; color:#000;">
</th>
<th style="background-color: #2e4e8e;color: #fff;"> <br><br>
<button input type="submit" class="btn btn-primary">Buscar</button>
</th>
<th style="background-color: #2e4e8e;color: #fff;"> </th>
</form>
</tr>
<?php
while ($result = mysqli_fetch_array($sql)) {
?>
<tr align="center">
<td><?php echo $result['RAZAO_SOCIAL']; ?></td>
<td><?php echo $result['CNPJ'] . " "; ?></td>
<td>
<a style="text-align: center;" href="clientealtera.php?id=<?php echo $result['IDCLIENTE']; ?>">
<span class="">Alterar</span><br>
</a>
</td>
<td>
<a href="" data-toggle="modal" data-target="#ExemploModalCentralizado">
Excluir
</a>
<div class="modal fade" id="ExemploModalCentralizado" tabindex="-1" role="dialog" aria-labelledby="TituloModalCentralizado" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" align="left"><strong>Confirmação de exclusão</strong></h4>
</div>
<div class="modal-body" align="left">
Deseja realmente excluir o cliente selecionado?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
<a href="clientedelete.php?id=<?php echo $result['IDCLIENTE']; ?>"><button type="submit" class="btn btn-primary">Confirmar</button> </a>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</table>
</div>
NOTE: If you put the function href="clientedelete.php? id=" inside the delete button outside the modal, it takes the correct id for deletion.
It worked out! Thank you very much!
– Matheus Melli