I am making an insertion to a database and would like that automatically after the INSERT the PHP file will get the ID that corresponds to the record (ID_PLANILLA).
This I need since I must automatically show a graph with the data obtained.
EH thought of something like getting the last ID in the database and adding 1, but I do not know how to do it.
PHP insert:
$stmt = $conexion->prepare("INSERT INTO sanciones (
unidad,
cedula_sancionado,
cedula_sancionador,
cedula_superior,
articulo_falta,
aparte_falta,
documento_seleccion,
fecha_inicio,
fecha_termino,
dias_sancion,
aclaratoria_sancion,
estado_sancion_id,
medida_id,
articulo_circunstancias,
agravante_seleccion,
atenuante_seleccion,
total_medida,
total_demerito_final,
estado_lugar_id)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("siiiiisssisiiissddi",
$unidad,
$cedula1,
$cedula2,
$cedula3,
$articulo_falta,
$aparte_falta,
$documentos_implode,
$fecha_inicio,
$fecha_termino,
$dias,
$aclaratoria,
$estado_sancion_id,
$tipo_medida,
$tipo_circunstancia,
$agravantes_implode,
$atenuantes_implode,
$total_medida,
$total_demerito_final,
$lugar);
$stmt->execute();
if ($stmt)
{
$idplanilla= lastid
echo ('<script>alert("Datos insertados satisfactoriamente!");</script>');
echo ("<script>window.location = 'grafica_unidades.php?idplanilla=<?=$idplanillla?>"
$stmt->close();
}
else
{
echo ('<script>alert("No se pudo generar la OMD");</script>');
echo ("<script>window.location = 'menu_generar_omd_unidades.php';</script>");
}