I am sending the data of a form, through ajax and php to my database:
If I try a single variable or 2, if it works, if I add the rest, it does not work.
My Ajax code is as follows:
$.ajax({
type: 'POST',
url: 'php/enviar_pedido.php',
data: {'referencia': referencia,
'detalles': detallesCi,
'tipo': tipoCi,
'combi': combiCi,
'familiaOD': familiaOD,
'disenyoOD': disenyoODCi,
'pasilloOD': pasilloODCi,
'indiceOD': indiceODCi,
'materialOD': materialODCi,
'tratamientoOD': tratamientoODCi,
'familiaOI': familiaOICi,
'disenyoOI': disenyoOICi,
'pasilloOI': pasilloOICi,
'indiceOI': indiceOICi,
'materialOI': materialOICi,
'tratamientoOI': tratamientoOICi,
'EjeOD': EjeODCi,
'CylOD': CylODCi,
'SphOD': SphODCi,
'AddOD': AddODCi,
'DnpOD': DnpODCi,
'HOD': HODCi,
'EjeOI': EjeOICi,
'CylOI': CylOICi,
'SphOI': SphOICi,
'AddOI': AddOICi,
'DnpOI': DnpOICi,
'HOI': HOICi,
'ColoracionOD': ColoracionODCi,
'EspejadoOD': EspejadoODCi,
'BaseEspecialOD': BaseEspecialODCi,
'EspesorBordeOD': EspesorBordeODCi,
'ColoracionOI': ColoracionOICi,
'EspejadoOI': EspejadoOICi,
'BaseEspecialOI': BaseEspecialOICi,
'EspesorBordeOI': EspesorBordeOICi
}
})
.done(function(listas_rep){
alert('Pedido enviado con éxito');
})
.fail(function(){
alert('Error 01')
})
The file send_pedido.php is as follows:
(The normal connection data) + through $ _POST [] .. I define all the variables:
$referencia = ($_POST['referencia']);
$detalles = ($_POST['detalles']);
$tipo = ($_POST['tipo']);
$combi = ($_POST['combi']); . . . .
mysqli_select_db($conexion, $dbname) or die ('No se encuentra la base de datos.');
mysqli_set_charset($conexion, 'utf8');
$sql = "INSERT INTO historial (referencia, detalles, tipo) VALUES (?,?,?)";
$resultado = mysqli_prepare($conexion, $sql);
$ok = mysqli_stmt_bnind_param($resultado, "sss", $referencia, $detalles, $tipo);
$ok = mysqli_stmt_execute($resultado);
if ($ok == false) {
alert('Error en la consulta SQL');
console_log( $resultado);
} else {
alert('Pedido enviado correctamente');
mysqli_stmt_close($resultado);
console_log($resultado);
}
The thing is that if I try with only a couple of variables, it gives me OK and inserts it.
This way, you do not even send me the error alert, but it does not send to the database either.
Any ideas of what may be happening? Thank you very much in advance, and regards.
FAILURE:
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort
:
ƒ (a)
always
:
ƒ ()
catch
:
ƒ (a)
done
:
ƒ ()
fail
:
ƒ ()
getAllResponseHeaders
:
ƒ ()
getResponseHeader
:
ƒ (a)
overrideMimeType
:
ƒ (a)
pipe
:
ƒ ()
progress
:
ƒ ()
promise
:
ƒ (a)
readyState
:
4
responseText
:
"No se encuentra la base de datos."
setRequestHeader
:
ƒ (a,b)
state
:
ƒ ()
status
:
200
statusCode
:
ƒ (a)
statusText
:
"OK"
then
:
ƒ (b,d,e)
__proto__
:
Object