Quantcast
Channel: Problema al insertar datos con ajax - Stack Overflow en español
Viewing all articles
Browse latest Browse all 2

Problema al insertar datos con ajax

$
0
0

Mi problema en si no es el insertar datos, dado a que estos se hacen de manera exitosa, el problema radica en que al insertar un dato, este se repite 2,3 o hasta 4 veces en la base de datos, otra cosa es que al entrar a la pagina y hacerlo por primera vez, este lo hace normal, pero mientras se hace este proceso como a la 3 vez de inserta datos, estos comienzan a repetirse. Dejo el código aquí abajo para ver si alguien puede ayudarme.

function insertar(){                         $.ajax({                          type : 'POST',              url  : '../indemnizaciones/tramite/Tinsertar.php',              data: $('#form').serialize(),              cache: false,              success :  function(data) {                                   $("#Tresul").html(data).fadeIn();},              complete: function(){                   setTimeout(function() {                    $('#Tresul').fadeOut();}, 10000);}})};
<?php error_reporting(0); ?><div id="formulario"><center><div id="Tresul"></div></center><br>  <form method="POST" id="tramite"><input type="text" name="predio" style="display:none; " value="<?php echo $formulario['TPRE_IDPRE']; ?>"><div class="row"><div class="col-md-3 col-md-offset-1" style="margin-left: 250px;"><label>Oficio notificacion</label><br><input type="text" name="oficioN" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_NONOT'] <> "") { ?> value="<?php echo $formularioT['TTRA_NONOT']; ?>"<?php } ?> ><br><br><label>Oficio solicitud autorizacion</label><br><input type="text" name="oficioS" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_NSAUT'] <> "") { ?> value="<?php echo $formularioT['TTRA_NSAUT']; ?>"<?php } ?>><br><br><label>Oficio autorizacion</label><br><input type="text" name="oficioA" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_NOAUT'] <> "") { ?> value="<?php echo $formularioT['TTRA_NOAUT']; ?>"<?php } ?>><br><br><br></div><div class="col-md-3 col-md-offset-1"><label>Fecha entrega notificacion</label><br><input type="date" name="fechaN" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_FENOT'] <> "") { ?> value="<?php echo $formularioT['TTRA_FENOT']; ?>"<?php } ?>><br><br><label>fecha solicitud autorizacion</label><br><input type="date" name="fechaA" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_FSAUT'] <> "") { ?> value="<?php echo $formularioT['TTRA_FSAUT']; ?>"<?php } ?>><br><br><label>fecha recepcion</label><br><input type="date" name="fechaR" style="height: 30px; width: 80%;"<?php if( $formularioT['TTRA_FAUTP'] <> "") { ?> value="<?php echo $formularioT['TTRA_FAUTP']; ?>"<?php } ?>><br><br><br></div></div><center><br><center><br><button type="button" onclick="insertar();" id="boton">Guardar</button></form></div>

<?phprequire("../../conexion.php"); $predio = $_POST['predio'];  $oficioN= $_POST['oficioN'];  $oficioS = $_POST['oficioS'];  $oficioA = $_POST['oficioA'];  $fechaN = $_POST['fechaN'];  $fechaA = $_POST['fechaA'];  $fechaR = $_POST['fechaR'];  $comprobar="SELECT * FROM ttramite WHERE TTRA_IDPRE='$predio';"; $compro=$mysqli->query($comprobar);  if($compro->num_rows==0){    $consulta = "INSERT INTO ttramite (TTRA_NONOT,TTRA_FENOT,TTRA_NSAUT,TTRA_FSAUT,TTRA_NOAUT,TTRA_FAUTP,TTRA_IDPRE) VALUES ('$oficioN','$fechaN','$oficioS','$fechaA','$oficioA','$fechaR','$predio');";    if($resultado = $mysqli->query($consulta)){     echo "<h5 style='color:#06A322;'>Registro guardado correctamente</h5>";    } else {    echo "<h5 style='color:#A30606;'>Imposible guardar, ocurrio un error</h5>";    } }else{$consultaD="UPDATE ttramite SET TTRA_NONOT='$oficioN',TTRA_FENOT='$fechaN',TTRA_NSAUT='$oficioS', TTRA_FSAUT='$fechaA',TTRA_NOAUT='$oficioA',TTRA_FAUTP='$fechaR' WHERE TTRA_IDPRE='$predio';";if($resultadoD = $mysqli->query($consultaD)){        echo "<h5 style='color:#0280BF;'>Registro modificado correctamente</h5>";} else {         echo "<h5 style='color:#A30606;'>Imposible modificar, ocurrio un error</h5>";} }$mysqli->close();?>

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images