I try to explain, since it is something I had never done before:
-
Attempt: when opening a modal, I take out an "id" (the one of the client)
-
Now, I try to send that "id" to the same page that had made the action, I put the code here:
$(document).on('click', '.editarCliente', function () { var id = $(this).attr("id"); console.log(id); $.ajax({ type: 'POST', url: 'php/editar_cliente.php', data: {'id': id} }) .done(function(listas_rep){ $('#resultEditCliente').html(listas_rep) }) .fail(function(err){ console.log(err); alert(err); }) $(document).on('click', '#cerrarEditarCliente', function () { $('#editarCliente').hide(); }); });
Why do I use this? Because I try, now on the clients page: create the following query:
<?php
require_once 'php/conexion.php';
function editarCliente() {
$idcliente = $_POST['id'];
$mysqli = getConn();
$query = "SELECT * FROM clientes WHERE id_cliente = $idcliente";
$result = $mysqli->query($query);
$ec = '<form id="form_edit_cliente" method="POST">
<table id="table" width="100%" class="table table-hover table-mc-light-blue">';
while($row = $result->fetch_array(MYSQLI_ASSOC)){
$ec .= '<h2>Editar cliente #'.$row[id_cliente].'</h2>
<h3>Datos Personales</h3>
<input id="idc" type="hidden" value="'.$row[id_cliente].'">
<table>
<tr>
<td class="campoP">Nombre</td>
<td class="td"><input id="nombre" type="text" value="'.$row[nombre].'"></td>
<td class="td barcode" style="text-align:center" colspan="6" rowspan="2"></td>
<td class="campoP">Fecha Registro:</td>
<td class="td">' .$row[fecha_registro]. '</td>
</tr>
<tr>
<td class="campoP">Apellidos</td>
<td class="td"><input id="apellidos" type="text" value="'.$row[apellidos].'"></td>
<td class="td" colspan="5"></td>
<td class="td"></td>
</tr>
<tr>
<td class="campoP">Telefono</td>
<td class="td"><input id="telefono" type="text" value="'.$row[telefono].'"></td>
<td class="td" colspan="5"></td>
<td class="td"></td>
</tr>
<tr>
<td class="campoP">Email</td>
<td class="td"><input id="email" type="text" value="'.$row[email].'"></td>
<td class="td" colspan="5"></td>
<td class="td"></td>
</tr>
</table>
<h3>Datos Comerciales</h3>
<table>
<tr>
<td class="campoP" style="width: 10%">Nombre Comercial</td>
<td class="td" style="width: 25%"><input id="ncomercial" type="text" value="'.$row[ncomercial].'"></td>
<td class="td" colspan="5"></td>
<td class="campoP" style="width: 10%">Nombre Fiscal</td>
<td class="td" style="width: 25%"><input id="nfiscal" type="text" value="'.$row[nfiscal].'"></td>
<td class="campoP">NIF/CIF</td>
<td class="td"><input id="cif" type="text" value="'.$row[cif].'"></td>
</tr>
<tr>
<td class="campoP">Direccion</td>
<td class="td"><input id="direccion" type="text" value="'.$row[direccion].'"></td>
<td class="td" colspan="5"></td>
<td class="campoP">Ciudad</td>
<td class="td"><input id="ciudad" type="text" value="'.$row[ciudad].'"></td>
<td class="campoP">CP</td>
<td class="td"><input id="cp" type="text" value="'.$row[cp].'"></td>
</tr>
</table>';
}
$ec .= '</table>
<br><br>
<center><input type="submit" id="submit" value="Editar Cliente"></center>
</form>';
return $ec;
}
echo editarCliente();
?>
He returns this to me by console:
jquery.min.js:4 POST http://localhost:8888/seoagency/php/editar_cliente.php 500 (Internal Server Error)
By doing this, everything stops working.
Does anyone think of how to help me? Thanks.