Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/02/2010, 16:45
SandWich
 
Fecha de Ingreso: febrero-2010
Mensajes: 17
Antigüedad: 14 años, 2 meses
Puntos: 0
Nuevo problema de variables, necesito ayuda

Bueno esto es parte del codigo de un miniforo que estoy haciendo para aprender a manejar variables y demas ya que llevo 2 semanas y media programando en php.

Va todo perfectamente hasta el insert del case 2, e tenido que pasar 2 variables como $_session ya que perdia el contenido de las mismas porque despues de recogerlas habian un par de submits por enmedio y las perdia.

En el insert de el case 1 me pilla perfectamente el $_SESSION['lol'], y despues intentando hacer lo mismo en el case 2 me sigue cojiendo bien $_SESSION['lol'] que se refiere al IDFORO pero el $_SESSION['lal'] nose porque me lo deja vacio a la hora de hacer el insert, el problema es que al no poder guardar el idtema no puedo despues mostrar donde tiene que ser su contenido, bueno sin mas dilación hos dejo el codigo.

Código PHP:
//Dibuja los hilos del foro
    
            include("conexionbdd.php");
            $sql = "SELECT DISTINCT IDFORO FROM foro1";
            $resultado = mysql_query($sql)
                        or die("No se pudo consultar la lista de hilos del foro");
                while ($fila = mysql_fetch_array($resultado))
                {    
                    echo "    <center><table bgcolor='#FF0000' width='100%' border='5' cellspacing='3' cellpadding='3'>";
                    echo "  <tr>";
                    echo " <th bgcolor='#99CC00' scope='col'><a href='forov02.php?da=1&lol=".$fila['IDFORO']."' style='color : blue'>$fila[IDFORO]</a></th>";
                    echo "  </tr>";
                    echo "</table></center>";
                }    
                        
?>    
        </th>
        <th width="75%" bgcolor="#0099FF" scope="col">&nbsp;</th>
        
<?php    

        
switch($_GET['da'])
        {    
            case 
1://Dibuja los temas del hilo seleccionado
                
if (@$_SESSION['auth'] != "si")
                {
                    
header("Location: logeo.html");
                }else
                 {
                    include(
"conexionbdd.php");
            
            
                    echo 
"<th width='10%' bgcolor='#0099FF' scope='col'>
                        <form action='forov02.php?da=1' method='post'>
                            <input type='submit' name='escribir' value='Nuevo tema'>
                        </form>
                                </th>
                              </tr>
                              <tr>
                        <th height='580' colspan='2' bgcolor='#0099FF' scope='col'>"
;
                
                    if(isset(
$_POST['escribir']))
                    {
                            echo 
"  <form action = 'forov02.php?da=1' method='post'>";
                            echo 
"    <center><table width='603' height='446' border='5' cellpadding='3' cellspacing='3'></center>";
                            echo 
"        <tr>";
                            echo 
"          <th height='29' scope='row'>Tema:</th>";
                            echo 
"          <th height='29' colspan='2' scope='row'>
                                            <DIV ALIGN=left><input type='text' name='IDTEMA' size='40'></div></th>"
;
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "        <tr>";
                            echo 
"          <th height='29' scope='row'>TITULO:</th>";
                            echo 
"          <th height='29' colspan='2' scope='row'>
                                            <DIV ALIGN=left><input type='text' name='titulo' size='40'></div></th>"
;
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "        <tr>";
                            echo 
"          <th height='360' colspan='3' scope='row'><textarea name='comentario' rows='20' cols='100'></textarea></th>";
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "        <tr>";
                            echo 
"        <th width='76' height='35' scope='row'>
                                            <input type='hidden' name='escribir'>
                                            <input type='submit' name='subir' value='Subir'></th>"
;
                            echo 
"        <th width='408' scope='row'>";
                            echo 
"            </th></form>";    
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "    </table></form>";
                    
                        if(isset(
$_POST['subir']))
                        {    
                            
$session $_SESSION['IDUSUARIO'];
                            include(
"conexionbdd.php");    
                            
                            
$mysql_datetime date("Y-m-d H:i:s");
                            
$sql "INSERT INTO foro1(IDFORO, IDTEMA, USERNAME, COMENTARIO, FECHA, TITULO) VALUES('".$_SESSION['lol']."', '$_POST[IDTEMA]','$session', '$_POST[comentario]', '$mysql_datetime', '$_POST[titulo]' )";
                            
$resultadomysql_query($sql)
                                        or die (
"No se guardo el nuevo tema");
                                        
                            
header("Location: forov02.php");
                        
                        }
                            echo 
'  <br>';
                        }
                
                    if(!isset(
$_POST['escribir']))
                    {
                        
$_SESSION['lol'] = $_GET["lol"];
                    
$sql "SELECT * FROM foro1 WHERE IDFORO= '".$_GET["lol"]."' ORDER BY FECHA ASC";
                    
$resultado mysql_query($sql)
                                or die(
"No se pudo consultar la lista de temas");
                        while (
$fila mysql_fetch_array($resultado))
                        {
                        echo 
"    <center><table width='70%' height='15%' border='5' cellpadding='3' cellspacing='3'>";
                        echo 
"  <tr>";
                        echo 
"    <th width='7%' scope='row'>&nbsp;</th>";
                        echo 
"    <td width='63%'><a href='forov02.php?da=2&lal=".$fila['IDTEMA']."' style='color : blue'>$fila[IDTEMA]</a></td>";
                        echo 
"    <td width='20%'>$fila[USERNAME]</a></td>";
                        echo 
"    <td width='10%'>&nbsp;</td>";
                        echo 
"    </tr>";
                        echo 
"</table></center>";
                        }
                }
            }    
            break;
            
            case 
2://Dibuja los temas del hilo seleccionado
                
if (@$_SESSION['auth'] != "si")
                {
                    
header("Location: logeo.html");
                }else
                 {
                    include(
"conexionbdd.php");
            
            
                    echo 
"<th width='10%' bgcolor='#0099FF' scope='col'>
                        <form action='forov02.php?da=2' method='post'>
                            <input type='submit' name='escribir' value='ESCRIBIR'>
                        </form>
                                </th>
                              </tr>
                              <tr>
                        <th height='580' colspan='2' bgcolor='#0099FF' scope='col'>"
;
                
                    if(isset(
$_POST['escribir']))
                    {
                            echo 
"  <form action = 'forov02.php?da=1' method='post'>";
                            echo 
"    <center><table width='603' height='446' border='5' cellpadding='3' cellspacing='3'></center>";
                            
//echo "     <input type='hidden' name='lal' value='".$_SESSION['lal']."' ";
                            
                            
echo "        <tr>";
                            echo 
"          <th height='29' scope='row'>TITULO:</th>";
                            echo 
"          <th height='29' colspan='2' scope='row'>
                                            <DIV ALIGN=left><input type='text' name='titulo' size='40'></div></th>"
;
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "        <tr>";
                            echo 
"          <th height='360' colspan='3' scope='row'><textarea name='comentario' rows='20' cols='100'></textarea></th>";
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "        <tr>";
                            echo 
"        <th width='76' height='35' scope='row'>
                                            <input type='hidden' name='escribir'>
                                            <input type='submit' name='subir' value='Subir'></th>"
;
                            echo 
"        <th width='408' scope='row'>";
                            echo 
"            </th></form>";    
                            echo 
"        </tr>";
                            
/////////////////////////////
                            
echo "    </table></form>";
                    
                        if(isset(
$_POST['subir']))
                        {    
                            
$session $_SESSION['IDUSUARIO'];
                            include(
"conexionbdd.php");    
                            
                            
$mysql_datetime date("Y-m-d H:i:s");
                            
$sql "INSERT INTO foro1(IDFORO, IDTEMA, USERNAME, COMENTARIO, FECHA, TITULO) VALUES('".$_SESSION['lol']."', '".$_SESSION['lal']."','$session', '$_POST[comentario]', '$mysql_datetime', '$_POST[titulo]' )";
                            
$resultadomysql_query($sql)
                                        or die (
"No se guardo el mensage");
                                        
                            
header("Location: forov02.php");
                        
                        }
                            echo 
'  <br>';
                        }
                
                    if(!isset(
$_POST['escribir']))
                    {
                        
$_SESSION['lal'] = $_GET["lal"];
                    
$sql "SELECT * FROM foro1 WHERE IDTEMA= '".$_GET["lal"]."' ORDER BY FECHA ASC";
                    
$resultado mysql_query($sql)
                                or die(
"No se pudo consultar la lista mensages");
                        while (
$fila mysql_fetch_array($resultado))
                        {
                            echo 
"    <table width='806' bordercolorlight='#000099' bgcolor='#FF0000' align='center' border='5' cellspacing='3' cellpadding='3'>";
                            echo 
"  <tr>";
                            echo 
"    <th colspan='2' bgcolor='#99CC00' scope='row'>
                                        $fila[TITULO]</th>"
;
                            echo 
"  </tr>";
                            echo 
"  <tr>";
                            echo 
"    <th width='118' height='130' scope='row'>$fila[USERNAME]</th>";
                            echo 
"    <td width='653' bgcolor='white'>$fila[COMENTARIO]</td>";
                            echo 
"  </tr>";
                            echo 
"  <tr>";
                            echo 
"    <th height='26' scope='row'>$fila[FECHA]</th>";
                            echo 
"    <td bgcolor='#99CC00'>&nbsp;</td>";
                            echo 
"  </tr>";
                            echo 
"</table>     ";
                        }
                }
            }    
            break;
        }
espero que me podais ayudar, solucionando ese problema tendria ya mi miniforo enmarcha :).

Un saludo y gracias de antemano d^_^b.