Muchas gracias por tu atención!!
Si tengo el insert justo antes de acabar el for.Te adjunto el código un poco recortado, sé que es demasiado largo pero lo hice así por cuestión visual. A ver que te parece, tengo los 2 principales problemas comentados en el código.
Código PHP:
<?PHP
$conexion = mysql_connect ("localhost", "root", "")
mysql_select_db ("alvaro")
$instruccion = "select * from plantillasudoku";
$consulta = mysql_query ($instruccion, $conexion)
$nfilas = mysql_num_rows ($consulta);
if ($nfilas > 0)
{
for ($i=0; $i<$nfilas; $i++)
{
//si la consulta devuelve mas de una fila....me muestra todo en la misma pantalla, quiero que me salga
//primero una consulta, le doy a enviar, y luego la siguiente consulta, este es uno de los problemas.
$resultado = mysql_fetch_array ($consulta);
echo '<form method="POST">';// action="insercionalumno.php">';
echo '<table border="1" BORDERCOLOR="red" cellpadding="2" cellspacing="0" align="center">';
echo '<tr BORDERCOLOR="black">';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a1'] == 0)
{
echo '<input type="text" name="a1" size="2" maxlength="1">';
}
else
{
$res= $resultado['a1'];
echo '<input type="text" name="a1" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a2'] == 0)
{
echo '<input type="text" name="a2" size="2" maxlength="1">';
}
else
{
$res= $resultado['a2'];
echo '<input type="text" name="a2" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a3'] == 0)
{
echo '<input type="text" name="a3" size="2" maxlength="1">';
}
else
{
$res= $resultado['a3'];
echo '<input type="text" name="a3" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td align="center">';
if ($resultado['a4'] == 0)
{
echo '<input type="text" name="a4" size="2" maxlength="1">';
}
else
{
$res= $resultado['a4'];
echo '<input type="text" name="a4" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td align="center">';
if ($resultado['a5'] == 0)
{
echo '<input type="text" name="a5" size="2" maxlength="1">';
}
else
{
$res= $resultado['a5'];
echo '<input type="text" name="a5" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td align="center">';
if ($resultado['a6'] == 0)
{
echo '<input type="text" name="a6" size="2" maxlength="1">';
}
else
{
$res= $resultado['a6'];
echo '<input type="text" name="a6" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a7'] == 0)
{
echo '<input type="text" name="a7" size="2" maxlength="1">';
}
else
{
$res= $resultado['a7'];
echo '<input type="text" name="a7" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a8'] == 0)
{
echo '<input type="text" name="a8" size="2" maxlength="1">';
}
else
{
$res= $resultado['a8'];
echo '<input type="text" name="a8" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '<td bgcolor="#A4A4A4" align="center">';
if ($resultado['a9'] == 0)
{
echo '<input type="text" name="a9" size="2" maxlength="1">';
}
else
{
$res= $resultado['a9'];
echo '<input type="text" name="a9" size="2" maxlength="1" value="' . htmlspecialchars($res) . '" READONLY>';
}
echo '</td>';
echo '</tr>';
echo ' <form method="post">';// action="insercionalumno.php">';
echo '<input type="submit" value="Guardar">';
echo '</form>';
//el otro problema esta aqui, que al iniciar sin darle al boton guardar me lo guarda directamente en la base de datos
//con todo 0, pero a partir de la segunda vez me lo hace bien.
$ssql = "insert into alumnosudoku (a1,a2,a3,a4,a5,a6,a7,a8,a9)
values ('". $_POST["a1"]."','". $_POST["a2"]."','". $_POST["a3"]."','". $_POST["a4"]."','". $_POST["a5"]."','". $_POST["a6"]."',
'". $_POST["a7"]."','". $_POST["a8"]."','". $_POST["a9"]."')";
if(mysql_query($ssql,$conexion)){
echo "Insercion correcta";
}
else{
echo "Insercion incorrecta";
}
}
echo '</TABLE>';
echo '</form>';
}
else{
print ("La tabla esta vacia");
}
mysql_close ($conexion);
?>
Un Saludo!