
mysqli_insert_id
Publicado por OSVALDO (22 intervenciones) el 25/09/2017 03:03:24
Hola amigos, pregunte esto antes pero la respuesta que me dieron me dejo en el mismo lugar pues supongo la formule mal. La cosa es que tengo un form con bootstrap, en el cual digíto e inserto esos datos en una tabla, tabla que por cierto tiene un ID auto incremental. La pregunta, como dice el titulo, tiene que ver en como tomar esa variable con el ID y mostrarla una vez hecho el insert y sin salirme o refrescar el form, o en su defecto, mostrar la ID en un mensaje tipo modal y al cerrarlo, limpiar el form. Como verán, la idea es no salirme de la pagina del form, pues está embebida en otra pagina.
Acá les dejo un trozo del form y el php de la consulta. Gracias.
html del form
php consulta
Acá les dejo un trozo del form y el php de la consulta. Gracias.
html del form
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<form method="post" id="frEmpresa" action="php/insert_ot.php">
<section>
<article>
<div class="container">
<h3>Ingreso OT</h3>
<div class="row">
<div class="col-md-2">
<label for="ot" style="font-size: 11px">Nº OT</label>
<input type="text" name="ot" id="ot" value="" readonly="readonly" style=" font-size: 11px," maxlength="7" size="7" >
</div>
<div class="col-md-2">
<label class="" for="" style="font-size: 11px">Fecha Ingreso</label>
<input type="date" id="fec_ing" name="fec_ing" value="" style="font-size: 11px" maxlength="10" size="10">
<script type="text/javascript">
var ing1 = jQuery.noConflict();
ing1( document ).ready(function() {
ing1('#fec_ing').datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
</div>
<div class="col-md-2">
<label class="" for="" style="font-size: 11px">Fecha Termino</label>
<input type="date" id="fec_ter" name="fec_ter" value="" style="font-size: 11px" maxlength="10" size="10">
</div>
<div class="col-md-2">
<label class="" for="" style="font-size: 11px">Fecha Entrega</label>
<input type="text" id="fec_ent" name="fec_ent" value="" style="font-size: 11px" maxlength="10" size="10">
</div>
<div class="col-md-2">
<label class="" for="" style="font-size: 11px">Garantia</label>
<select name="gar" id="gar" style="font-size: 11px" >
<option>NO</option>
<option>HLS</option>
<option>BROTHER</option>
</select>
<!--<input type="text" id="gar" name="gar" value="" style="font-size: 11px" maxlength="10" size="10">-->
</div>
<div class="col-md-2">
<label class="" for="" style="font-size: 11px">Fecha Compra</label>
<input type="text" id="fec_comp" name="fec_comp" value="" style="font-size: 11px" maxlength="10" size="10">
<script type="text/javascript">
var comp1 = jQuery.noConflict();
comp1( document ).ready(function() {
comp1('#fec_comp').datepicker({
dateFormat: 'yy-mm-dd'
});
});
</script>
</div>
</div>
</div>
</article>
</section>
php consulta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
$conexion = new mysqli('localhost','root','','db_hlsr',3306);
$status = "";
if (isset($_POST["idclte"])) {
$idclte = $_POST["idclte"];
$fec_ing = $_POST["fec_ing"];
$fec_comp = $_POST["fec_comp"];
$tec = $_POST["tec"];
$gar = $_POST["gar"];
$tip = $_POST["tip"];
$idcon = $_POST["idcon"];
$serie = $_POST["serie"];
$cpag = $_POST["cpag"];
$tin = $_POST["tin"];
$modelo = $_POST["modelo"];
$equipo = $_POST["equipo"];
$marca = $_POST["marca"];
$sql = "INSERT INTO tb_ot (id_clte2,fec_ap, fec_comp, id_tec1,garantia,tipo,id_cont,serie,cont_pg,tinta,modelo,equipo,marca) ";
$sql.= "VALUES ('".$idclte."', '".$fec_ing."', '".$fec_comp."', '".$tec."', '".$gar."', '".$tip."', '".$idcon."', '".$serie."', '".$cpag."', '".$tin."', '".$modelo."', '".$equipo."', '".$marca."')";
//mysqli_query($conexion, $sql);
//$status = "ok";
//lo inserto en la base de datos
if (mysqli_query($conexion, $sql)){
$status = "ok";
//recibo el último id
$ultimo_id = mysqli_insert_id($conexion);
echo "EL NUMERO DE OT ES ", $ultimo_id;
//echo $_POST["ot"] = $ultimo_id;
}else{
echo "La inserción no se realizó";
}
}
?>
Valora esta pregunta


0