I'm with the edition of the orders through modal and AJAX.
The problem is that in the order table the "Product" field is a number, but in the modal I get the name of the product, eg: Diode Laser "thanks to a query that you make to get the name.
But of course when sending the data by modal like this:
With this I send it to the modal:
<td class="otrotdfgaz" id="Producto<?php echo $res['pedID']; ?>"><?php echo $res['producto']; ?> <?php echo $res['alias']; ?></td>
With this I print it in the modal:
<script>
$(document).ready(function(){
$(document).on('click', '.pedido', function(){
var id=$(this).val();
$('#pedido').modal('show');
$('#eProducto').val(Producto);
});
});
</script>
<input type="text" class="form-control inputmiocont corpiii" id="eProducto" name="eProducto">
Up there is really more data but I only put the one that interests you. Now we send it through AJAX:
<script>
$(function(){
$("#actPedido").on("submit", function(e){
e.preventDefault();
var f = $(this);
var formData = new FormData(document.getElementById("actPedido"));
formData.append("dato", "valor");
//formData.append(f.attr("name"), $(this)[0].files[0]);
$.ajax({
url: "pedidos/act-pedido.php",
type: "post",
dataType: "html",
data: formData,
cache: false,
contentType: false,
processData: false
})
.done(function(res){
$("#mensaje").html(res);
toastr["success"]("Pedido Actualizado", "Mensaje")
//setTimeout(function () {
// window.location.href = "ver-cliente.php?ID=<?php echo $res['IdUsuario']; ?>"; //will redirect to your blog page (an ex: blog.html)
// }, 1500); //will call the function after 2 secs
});
});
});
Then we do the update:
<?php include "../../conexion/conexion.php" ?>
<?php
$id = $_POST['eIdp'];
$producto = $_POST['Producto'];
$factura = $_POST['eNumero'];
$eFecha = $_POST['eFecha'];
$eVencimiento = $_POST['eVencimiento'];
$estado = $_POST['select2-1'];
$tipo = $_POST['select2-4'];
$total = $_POST['eTotal'];
$referencia = $_POST['select2-3'];
die()
$results = "Update pedidos Set Numero='$factura', Fecha='$eFecha', Vencimiento='$eVencimiento', Estado='$estado', Producto='$producto', Tipo='$tipo', Total='$total', Referencia='$referencia' where id= " .$_POST['eIdp'];
if ( !mysqli_query($mysqli, $results)) {
die( 'Error: ' . mysqli_error() );
}
mysqli_close($mysqli);
?>
So this is what the UPDATE does to me:
eIdp: 4
eNumero: 342342
eFecha: 2018-09-12
eVencimiento: 2018-09-30
select2-1: 0
eProducto: **Láser DualWave**
select2-4: 1
eTotal: 300.00€
select2-3: DW002
What is between asterisks should be a number so everything works fine. So I do not know how to make a query when updating the order so that it takes out the number through the name that comes out or through the order number. The same is something complex to understand but I do not know how to detail it better. Thanks