Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/04/2011, 08:38
Alvaros
 
Fecha de Ingreso: abril-2011
Mensajes: 37
Antigüedad: 13 años
Puntos: 0
Respuesta: Problema phpmyadmin

Muchas gracias por vuestra ayuda, probaré como me has dicho stramin, de todas formas adjunto el código y será más fácil que entendaís mi duda:
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);

?>
El código consiste en plantillas de sudokus que estan almacenadas en otra tabla, este es el código que las visualiza las plantillas y guarda la solución en la base de datos, adjunto parte del código, en el código están comentados los 2problemas principales que tengo.Muchas gracias por vuestra ayuda.

Un saludo!