Foros del Web » Programando para Internet » PHP »

Test online

Estas en el tema de Test online en el foro de PHP en Foros del Web. Bueno navegando por ahi y revisando muchos codigos me encontre con una implementación que trato de aplicar a mis fines bueno la primera parte es ...
  #1 (permalink)  
Antiguo 13/01/2010, 07:45
 
Fecha de Ingreso: diciembre-2009
Ubicación: La Paz - Bolivia
Mensajes: 67
Antigüedad: 14 años, 4 meses
Puntos: 1
Test online

Bueno navegando por ahi y revisando muchos codigos me encontre con una implementación que trato de aplicar a mis fines bueno la primera parte es hacer que el sistemita de test online funcione bien el drama esta en que no ubico donde estan los siguientes errores:
- La calificacion no es la adecuada (creo por que mando mal los datos del form)
- Cuando trato de generar preguntas con mas de una respuesta con checkboxs no me califica bien???
Dejo el código para recibir sugerencias.

Index.html
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Test de Conocimiento</title>
<
style type="text/css">
form{width:16empadding:1emmargin:autoborder:double 7px black; }
h3{font-size:1.4emcolor:bluetext-align:center; }
</
style>
<
script language="JavaScript"
function 
click()

  if (
event.button==2) { 
  
alert ('Este boton esta desabilitado.'
  } 

document.onmousedown=click 
</script>
 
</head>

<body>
<form method="post" action="examen.php">
 <h3>Ingresar al Sistema de Test</h3>
  Usuario: 
  <label>
  <input type="text" name="user" />
  </label>
  <p>Password: 
    <label>
    <input type="password" name="pss" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" value="Entrar" />
    </label>
</p>
</form>
</body>
</html> 
Examen.php
Código PHP:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test de Conocimiento</title>
<style>
h1{font:bold 1.3em Georgia, "Times New Roman", Times, serif;color:#c00;}
h3{font:bold Georgia, "Times New Roman", Times, serif;color: #000000;}
</style>
<script language="JavaScript"> 
function click() { 
if (event.button==2) { 
alert ('Este boton esta desabilitado.') 


document.onmousedown=click 
</script> 
</head>
<body>
<?
  $user 
= (isset($_POST['user'])?$_POST['user']:NULL);
  
$pass = (isset($_POST['pss'])?$_POST['pss']:NULL);
  
$numPregs 2// asegurarse q la bd tenga >=3 preguntas
  
$conexion mysql_connect("localhost","root");
  if(!
$conexion){
    echo 
"<p>Error: No se puede conectar al servidor</p>\n";
  }
  else{
    
$bd mysql_select_db("examenes",$conexion);
     if(!
$bd){
       echo 
"<p>Error: No se pudo seleccionar la bd</p>\n";
     }
     else if(
$user==null || $pass==null){
       echo 
"<center><h2>Error: Datos de login nulos</h2><br>\n";
       echo 
"<img src='como.gif'>";
       echo 
"<a href='Index.php'> Regresar al Inicio</a></center>\n";
     }
     else{
       
$nombre mysql_query("select nombre from usuarios where matricula='$user' and password='$pass'",$conexion);
       
$presento mysql_query("select presento from usuarios where matricula='$user' and password='$pass'",$conexion);
       if(
mysql_num_rows($nombre)<=0){
         echo 
"<center><h2>Autentificacion incorrecta<br></h2>\n";
         echo 
"<img src='paz.gif'>";
         echo 
"<a href=\"Index.php\"> Regresar al Inicio</a></center>\n";
       }
       else if(
mysql_result($presento,0,'presento')==1){
         echo 
"<center><h3>El Usuario ".mysql_result($nombre,0,'nombre')." email $user ya presento este test</h3><br>\n";
         echo 
"<img src='roja.gif'>\n";
         echo 
"<a href=\"Index.php\"> Regresar al Inicio</a></center>\n";
       }
       else{
             echo 
"<center><h1> Test de conocimientos de Manual de Actividades</h1><img src='mareo.gif'></center>\n";
             echo 
"<p><h3>Bienvenido Usuario ".mysql_result($nombre,0,'nombre')."</h3></p>\n";
         
// seleccionar las preguntas aleatoriamente
         
$pregsInBD mysql_query("select count(idp) as 'num' from preguntas",$conexion);
         
$pregsExistentes mysql_result($pregsInBD,0,'num');
         for(
$r=0;$r<$numPregs;$r++) $vector[$r]=0;
         for(
$r=0;$r<$numPregs;$r++){
               
$alea=rand(1,$pregsExistentes);
               
$bandera=true;
               for(
$f=0;$f<$r;$f++)
                 if(
$vector[$f]==$alea){
                   
$bandera=false;
                   break;
                 }
               if(!
$bandera){ $r--; continue; }
               
$vector[$r]=$alea;
             }
             
// cargar las preguntas
             
echo '<form action="califica.php" method="post">'."\n";
             for(
$r=0;$r<$numPregs;$r++){
               
$pregActu mysql_query("select preguntas from preguntas where idp='$vector[$r]'",$conexion);
               
$txtPregActu mysql_result($pregActu,0,'preguntas');
               
$tpPreg mysql_query("select tipo from preguntas where idp='$vector[$r]'",$conexion);
               
$tipoPreg mysql_result($tpPreg,0,'tipo');
               echo 
"<p>\n";
               echo 
"".($r+1).") ".$txtPregActu;
               if(
$tipoPreg==1){ // opcion multiple con mas de una respuesta correcta
                 
$consOps mysql_query("select idr from corresponde where idp='$vector[$r]'",$conexion);
                 
$numResp mysql_num_rows($consOps);
                 echo 
"\n<br>";
                 echo 
' <input type="hidden" name="preg'.($r+1).'" value="'.$vector[$r].'">'."\n";
                 for(
$hui=0;$hui<$numResp;$hui++){
                   
$consResp mysql_query("select respuesta from respuestas where idr='".mysql_result($consOps,$hui,'idr')."'",$conexion);
                   
$valormysql_result($consResp,0,'respuesta');
                   echo 
'<input type="checkbox" name="'.$r.'[]" value="'.$valor.'">'.$valor."<br>\n";
                   }
               }
               else{ 
// falso verdadero excluyente
                 
$consOps mysql_query("select idr from corresponde where idp='$vector[$r]'",$conexion);
                 
$numResp mysql_num_rows($consOps);
                 echo 
"\n<br>";
                 echo 
' <input type="hidden" name="preg'.($r+1).'" value="'.$vector[$r].'">'."\n";
                 for(
$hui=0;$hui<$numResp;$hui++){
                   
$consResp mysql_query("select respuesta from respuestas where idr='".mysql_result($consOps,$hui,'idr')."'",$conexion);
                   
$valormysql_result($consResp,0,'respuesta');
                   echo 
'<input type="radio" name="'.$r.'" value="'.$valor.'">'.$valor."<br>\n";
                 }
               }
               echo 
"</p>\n";
             }
             echo 
'<input type="hidden" name="mat" value="'.$user.'">'."\n";
             echo 
'<input type="submit" value="Calificar">'."\n";
             echo 
'</form>'."\n";
             
mysql_Close($conexion);
          }
      }
  }
?>

</body>
</html>
califica.php
Código PHP:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Calificacion</title>
</head>

<body>
<?
  
// $numPregs = 2; // asegurarse q la bd tenga >=3 preguntas
  // diseño estatico para solo revisar dos preguntas
  
$preg[0] = (isset($_POST['preg1'])?$_POST['preg1']:NULL);
  
$preg[] = (isset($_POST['preg2'])?$_POST['preg2']:NULL);
  
  
$respDada[0] = (isset($_POST['0'])?$_POST['0']:NULL);
  
$respDada[] = (isset($_POST['1'])?$_POST['1']:NULL);

  
  
$matricula = (isset($_POST['mat'])?$_POST['mat']:NULL);
  if(!
$preg||!$respDada||!$matricula){
    echo 
"<p>Acceso invalido</p>";
  }
  else{
    
$conexion mysql_connect("localhost","root");
    if(!
$conexion){
      echo 
"<p>Error: No se puede conectar al servidor<br>\n";
      echo 
"<a href=\"Index.php\"> Regresar al Inicio</a> </p>\n";
    }
    else{
      
$bd mysql_select_db("examenes",$conexion);
      if(!
$bd){
        echo 
"<p>Error: No se pudo seleccionar la bd<br>\n";
        echo 
"<a href=\"Index.php\"> Regresar al Inicio</a> </p>\n";
      }
      else{
        
$calif=0;
        
$consulta mysql_query("select nombre from usuarios where matricula='$matricula'",$conexion);
   
//     echo "<h2> Calificacion </h2>\n";
   //     echo "<p> Usuario ".mysql_result($consulta,0,'nombre')." usuario $matricula</p>\n";
        
for($cju=0;$cju<sizeof($preg);$cju++){
          
$consulta mysql_query("select idr from corresponde where idp='$preg[$cju] and sipi=1'",$conexion);
          
$idres mysql_result($consulta,0,'idr');
          
$consulta mysql_query("select respuesta from respuestas where idr='$idres'",$conexion);
          
$respuestidirijilla mysql_result($consulta,0,'respuesta');
          if(
$respDada[$cju]==$respuestidirijilla$calif+=1;
        }
        
mysql_query("update usuarios set calif='$calif', presento=1 where matricula='$matricula'",$conexion);
        
mysql_Close($conexion);
//        echo "<p>Ha obtenido una calificacion ".($calif>=1?"aprobatoria":"reprobatoria")." de $calif</p>";
        
echo "<center><h2>Gracias por rendir esta pequeña prueba</h2>";
        echo 
"<img src='ok.gif'>";
        echo 
"<a href=\"Index.php\"> Regresar al Inicio</a> </center>\n";
      }
    }
  }
?>

</body>
</html>
Bueno si alguien vee algun error sería de gran ayuda que me corrijan asi aprendo de una ves por todas de antemano gracias
  #2 (permalink)  
Antiguo 13/01/2010, 15:54
 
Fecha de Ingreso: diciembre-2009
Ubicación: La Paz - Bolivia
Mensajes: 67
Antigüedad: 14 años, 4 meses
Puntos: 1
Respuesta: Test online

Bueno me respondo ja.. ubique un pequeño error en la linea:
Código PHP:
$consulta mysql_query("select idr from corresponde where idp='$preg[$cju]' and sipi='1'",$conexion); 
          
$idres mysql_result($consulta,0,'idr'); 
la condicion en el where estaba medio mal..
Ahora bien me falta el chiste de los check box eso me esta matando...

Etiquetas: test
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 16:10.