Foros del Web » Programando para Internet » PHP »

Porque no me funciona este codigo???? alguien?'?

Estas en el tema de Porque no me funciona este codigo???? alguien?'? en el foro de PHP en Foros del Web. pues el error que me da es que si la tabla sql esta vacia no me muestra el formulario que es en estas lineas si ...
  #1 (permalink)  
Antiguo 01/03/2012, 13:32
Avatar de erick_reyesg  
Fecha de Ingreso: enero-2012
Ubicación: Guatemala
Mensajes: 53
Antigüedad: 12 años, 2 meses
Puntos: 2
Porque no me funciona este codigo???? alguien?'?

pues el error que me da es que si la tabla sql esta vacia no me muestra el formulario que es en estas lineas si el usuario ya esta en la tabla con la fecha de hoy muestra ya evaluado de lo contrario deberia mostrar el formulario pero no lo hace y le puse otra conexion porq? por q la db del form es diferenta ayuda plz

Código PHP:
if ($user == $usuario  && $fech == $fecha){
        echo 
"<p style='font-family:Tahoma, Geneva'><b>Ya Te Evaluaste Hoy tu nota es $not</b></p> <br><br>";
        echo 
"<a href='form.php'>    <img src='images/volver.png' /></a>";
        return 
0;
           }
           else{
$conexion mysql_connect("localhost""root""ene2012");
    
mysql_select_db("usuarios"$conexion);
    
$queEmp "SELECT * FROM cuestionario";
    
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
    
$totEmp mysql_num_rows($resEmp);      
echo 
"<form action='resultado.php' method='post' name='formulario'>";
echo 
"<table>";

       while (
$rowEmp mysql_fetch_assoc($resEmp)) {
       
$corre1 $rowEmp['corre1'];
       
$corre2 $rowEmp['corre2'];
       
$corre3 $rowEmp['corre3'];
       
$corre4 $rowEmp['corre4'];        
           
          echo 
"<strong>".$rowEmp['pregunta1']."</strong><br>";
          echo 
"<tr><td><input type='radio' name='Res1' value='1'>";
          echo 
"".$rowEmp['1res1']."<br>";
    echo 
"<input type='radio' name='Res1' value='2'>";
          echo 
"".$rowEmp['1res2']."<br>"
    echo 
"<input type='radio' name='Res1' value='3'>";
          echo 
"".$rowEmp['1res3']."<br>"
    echo 
"<input type='radio' name='Res1' value='4'>";
          echo 
"".$rowEmp['1res4']."<br></td></tr>";   
echo 
"</table><br>"



Código PHP:
    <?php
    $usuario 
$_COOKIE['loggedin'];
    if (!isset(
$_COOKIE['loggedin'])) die("<center><img src='images/error.png'><br><div id='miclase'>No te has identificado, <a href=index.html>click ac&aacute;</a> para iniciar sesi&oacute;n.</center>");
     
                 
$conexion mysql_connect("localhost""root""ene2012");
        
mysql_select_db("usuarios"$conexion);
        
$queEmp "SELECT * FROM notas_cues WHERE usuario ='$usuario'"// WHERE usuario ='$usuario'
        
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
        
$totEmp mysql_num_rows($resEmp);  
        
$nom $qry['nombre'];
//$jdv = $qry['jjvv'];
    
echo "Usuario: <input type='text'  name='matricula' size='8' readonly value='$usuario'>&nbsp;&nbsp;&nbsp;";
//echo "    <input type='text' name='nombre' value='$nom'>";
//echo "    <input type='text' name='jefe' value='$jdv'>";




    
echo "Fecha &nbsp;&nbsp;&nbsp;";
    
$fecha date('d/m/y');
    echo 
$fecha;
    echo 
"<br><br>";


           while (
$rowEmp mysql_fetch_assoc($resEmp)) {
    
$not $rowEmp['nota'];
    
$user $rowEmp['usuario'];
    
$fech $rowEmp['fecha'];
     
    if (
$user == $usuario  && $fech == $fecha){
        echo 
"<p style='font-family:Tahoma, Geneva'><b>Ya Te Evaluaste Hoy tu nota es $not</b></p> <br><br>";
        echo 
"<a href='form.php'>    <img src='images/volver.png' /></a>";
        return 
0;
           }
           else{
$conexion mysql_connect("localhost""root""ene2012");
    
mysql_select_db("usuarios"$conexion);
    
$queEmp "SELECT * FROM cuestionario";
    
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
    
$totEmp mysql_num_rows($resEmp);      
echo 
"<form action='resultado.php' method='post' name='formulario'>";
echo 
"<table>";

       while (
$rowEmp mysql_fetch_assoc($resEmp)) {
       
$corre1 $rowEmp['corre1'];
       
$corre2 $rowEmp['corre2'];
       
$corre3 $rowEmp['corre3'];
       
$corre4 $rowEmp['corre4'];        
           
          echo 
"<strong>".$rowEmp['pregunta1']."</strong><br>";
          echo 
"<tr><td><input type='radio' name='Res1' value='1'>";
          echo 
"".$rowEmp['1res1']."<br>";
    echo 
"<input type='radio' name='Res1' value='2'>";
          echo 
"".$rowEmp['1res2']."<br>"
    echo 
"<input type='radio' name='Res1' value='3'>";
          echo 
"".$rowEmp['1res3']."<br>"
    echo 
"<input type='radio' name='Res1' value='4'>";
          echo 
"".$rowEmp['1res4']."<br></td></tr>";   
echo 
"</table><br>";
 
 
echo 
"<table>";
          echo 
"<strong>".$rowEmp['pregunta2']."</strong><br>";
          echo 
"<tr><td><input type='radio' name='Res2' value='1'>";
          echo 
"".$rowEmp['2res1']."<br>";
    echo 
"<input type='radio' name='Res2' value='2'>";
          echo 
"".$rowEmp['2res2']."<br>"
    echo 
"<input type='radio' name='Res2' value='3'>";
          echo 
"".$rowEmp['2res3']."<br>"
    echo 
"<input type='radio' name='Res2' value='4'>";
          echo 
"".$rowEmp['2res4']."<br></td></tr>";   
echo 
"</table><br>";
echo 
"<br>";
 
 
 
echo 
"<table>";
          echo 
"<strong>".$rowEmp['pregunta3']."</strong><br>";
          echo 
"<tr><td><input type='radio' name='Res3' value='1'>";
          echo 
"".$rowEmp['3res1']."<br>";
    echo 
"<input type='radio' name='Res3' value='2'>";
          echo 
"".$rowEmp['3res2']."<br>"
    echo 
"<input type='radio' name='Res3' value='3'>";
          echo 
"".$rowEmp['3res3']."<br>"
    echo 
"<input type='radio' name='Res3' value='4'>";
          echo 
"".$rowEmp['3res4']."<br></td></tr>";   
echo 
"</table><br>";

 
echo 
"<input type='image' src='images/nota.png' />";
echo 
"</form>";

       }
              }
    }

    
?>
__________________
No hay Mayor señal de Ignoracia que creer imposible lo Inexplicable
  #2 (permalink)  
Antiguo 02/03/2012, 01:30
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Porque no me funciona este codigo???? alguien?'?

Sigues utilizando nombres de variables repetidos en whiles anidados:


Código PHP:
Ver original
  1. while ($rowEmp = mysql_fetch_assoc($resEmp)) {
  2.     $not = $rowEmp['nota'];
  3.     $user = $rowEmp['usuario'];
  4.     $fech = $rowEmp['fecha'];
  5.      
  6.     if ($user == $usuario  && $fech == $fecha){
  7.         echo "<p style='font-family:Tahoma, Geneva'><b>Ya Te Evaluaste Hoy tu nota es $not</b></p> <br><br>";
  8.         echo "<a href='form.php'>    <img src='images/volver.png' /></a>";
  9.         return 0;
  10.     }
  11.     else{
  12.         $conexion = mysql_connect("localhost", "root", "ene2012");
  13.         mysql_select_db("usuarios", $conexion);
  14.         $queEmp = "SELECT * FROM cuestionario";
  15.         $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
  16.         $totEmp = mysql_num_rows($resEmp);
  17.         echo "<form action='resultado.php' method='post' name='formulario'>";
  18.         echo "<table>";
  19.  
  20.         while ($rowEmp = mysql_fetch_assoc($resEmp)) {
__________________
Fere libenter homines, id quod volunt, credunt.

Etiquetas: formulario, html, mysql, sql, tabla, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:46.