I have not been able to solve the following problem, I have a form which is valid with smoke.js in the following way:
$('#btn_guardar').click(function () {
if ($('#form_datos').smkValidate()) {
var datos = 'nombreUno=' + $('#nombreUno').val() +
'&nombreDos=' + $('#nombreDos').val() +
'&apellidoUno=' + $('#apellidoUno').val() +
'&apellidoDos=' + $('#apellidoDos').val() +
'&personal=1';
$.ajax({
type: 'POST',
url: 'formulario.php',
data: datos
}).done(function (data) {
if (data == 1) {
$.smkAlert({
text: 'Se actualizaron correctamente los datos',
type: 'success',
});
} else {
$.smkAlert({
text: 'Se presento un problema intente de nuevo',
type: 'danger'
});
}
});
}
});
With the data of the form I updated a table in Mysql and after updating the data I made a new query to the database and again depending on the result it takes me to one or another page, but although it updates the data the query is skipped and throws me the smkAlert danger that is in the script when a problem occurs.
This is the query I use:
$smtr=$db->prepare('UPDATE persona SET nombreUno=:nombreUno,nombreDos=:nombreUno,apellidoUno=:apellidoUno,apellidoDos=:apellidoDos WHERE usuario=:usuario');
$smtr->bindValue('nombreUno',$_POST['nombreUno']);
$smtr->bindValue('nombreDos',$_POST['nombreDos']);
$smtr->bindValue('apellidoUno',$_POST['apellidoUno']);
$smtr->bindValue('apellidoDos',$_POST['ApellidoDos']);
$smtr->bindValue('usuario',$_SESSION['usuario']);
$smtr->execute();
if($smtr){
echo 1;
$consulta=$db->prepare('SELECT estado FROM persona WHERE usuario=:usuario');
$consulta->bindValue('usuario',$_SESSION['usuario']);
$consulta->execute();
$resultado=$consulta->fetch(PDO::FETCH_ASSOC);
if($resultado['estado']==1){
header('location:index.php');
}else{
header('location:formulario.php');
}
}else{
echo 0;
}
What happens is that the SELECT
is not executed. What changes could you implement?