I try to do the following:
-
When you send a FORM , you generate an order, which, through Ajax, you send to the database.
-
Next, I have another Ajax, (both in jQuery when submitting) that pulls out a csv file from the order:
<?php $cod_cliente = ($_POST['cod_cliente']); $optica = ($_POST['optica']); $fecha = ($_POST['fecha']); $tipo = ($_POST['tipo']); $csv = "../pedidos/PEDIDO ".$tipo.".csv"; $lista = array ( array('Codigo Cliente', 'Cliente', 'Fecha', 'Tipo'), array($cod_cliente, $optica, $fecha, $tipo), ); $fp = fopen($csv, 'x'); foreach ($lista as $campos) { fputcsv($fp, $campos); } fclose($fp);
? >
The complete ajax : submit:
$("#pedidos").submit(function(e){
// Aquí definidas todas las variables
e.preventDefault();
$.ajax({
type: 'POST',
url: 'php/enviar_pedido.php',
data: {'cod_cliente': cod_cliente,
...etc
}
})
.done(function(listas_rep){
})
.fail(function(){
})
$.ajax({
type: 'POST',
url: 'php/generarCsv.php',
data: {'cod_cliente': cod_cliente,
'optica': optica,
'fecha': fecha,
'tipo': tipoCi}
})
.done(function(listas_rep){
alert('CSV Generado con exito');
})
.fail(function(){
alert('Error al crear el archivo CSV')
})
})
My question is this: this request is sent in turn that generates the csv file.
If you notice, the name of the csv file is: ORDER "type", even though what I need is that you get the format of: "ORDER 01" "ORDER 02"
- The ID of the order is supposed to be a
AUTOINCREMENT
in the database, so there is the "ID" but theCSV
I generate it at the moment I create the order, obviously, in that moment is not yet the ID.
Can someone please offer me some advice / solution?