Tengo un script php que inserta datos en la BBDD mysql que le llegan de un form html (lo clásico) con insert into y luego otro script php lee la BBDD pero no lista el último dato insertado hasta que actualizo la página. Cuando llamo al script que lista los datos ya está insertado el último dato pero no lo muestra salvo que la llame otra vez. Si listo los registros en el script 1 salen todos pero cuando voy al script 2 falta el último. He probado a meter un error en el script 2 y no da error hasta que doy F5 de modo que no está leyendo el script ¿quizás del buffer?
Script 1 El que introduce datos desde el formulario html
include "conexion.php";
$obs_exp="";
$fecha_fin_exp="0/0/0000";
$punto=$_POST['punto'];
$tipo=$_POST['tipo'];
$estado=$_POST['estado'];
$categoria=$_POST['categoria'];
$fecha_inicio_exp=$_POST['fecha_inicio_exp'];
If (isset($_POST['fecha_fin_exp'])) $fecha_fin_exp=$_POST['fecha_fin_exp'];
If (isset($_POST['obs_exp'])) {$obs_exp=$_POST['obs_exp'];}
If (isset($_POST['email'])) {$email=$_POST['email'];}
if (isset($_POST['punto'])){
$query="insert into incidenciasListado (punto,tipo,categoria,estado,fecha_inicio,fecha_fin,obs_exp) values ('$punto','$tipo','$categoria','$estado','$fecha_inicio_exp','$fecha_fin_exp','$obs_exp') ";
$res=mysqli_query($con,$query);
}
Script 2: El que lista los datos
<?php
include "conexion.php";
$query="select num,punto,tipo,categoria,estado,fecha_inicio,fecha_fin,obs_exp from incidenciasListado order by num";
$res=mysqli_query($con,$query);
//$fila=mysqli_fetch_row($res);
echo "<table>";
echo "<tr>";
echo "<th> num </th>";
echo "<th> punto </th>";
echo "<th> tipo </th>";
echo "<th> estado </th>";
echo "<th> categoria </th>";
echo "<th> fecha inicio </th>";
echo "<th> fecha fin </th>";
echo "<th> observaciones </th>";
echo "<th> acceder </th>";
echo "</tr>";
while($fila=mysqli_fetch_row($res)){
echo "<tr>";
$fecha=date_create($fila[5]);
$fecha1=date_format($fecha,'d/m/Y');
if ($fecha1=="30/11/-0001") $fecha1="";
$fecha=date_create($fila[6]);
$fecha2=date_format($fecha,'d/m/Y');
if ($fecha2=="30/11/-0001") $fecha2="";
echo "<td> ".$fila[0]."</td>";
echo "<td>" .utf8_encode($fila[1])."</td>";
echo "<td>" .utf8_encode($fila[2])."</td>";
echo "<td>" .utf8_encode($fila[3])."</td>";
echo "<td>" .utf8_encode($fila[4])."</td>";
echo "<td>" .$fecha1."</td>";
echo "<td>" .$fecha2."</td>";
echo "<td>" .utf8_encode($fila[7])."</td>";
echo "<td><a href='aporteincidencia.php?num=".$fila[0]."'> acceder </a></td>";
echo"</tr>";
}
echo "</table>";
?>
Script conexion.php:
$con=mysqli_connect($host,$user,$pass,$bd);
mysqli_set_charset($con,"UTF-8");
// errores conexion
if (mysqli_connect_errno()){
echo"Error en la conexión";
exit();}
mysqli_select_db($con,$bd) or die("Error en la conexión a la BD");