Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/07/2014, 16:06
choco_cu
 
Fecha de Ingreso: mayo-2004
Ubicación: Ciudad de la Habana
Mensajes: 85
Antigüedad: 20 años
Puntos: 0
Problema para insertar datos en base de datos

Hola amigos de foros del web. Es el segundo problema que tengo que presentarles a ustedes desde que comenze a realizar este proyecto. Esta vez si he revisado todas las posibilidades y estoy ciego porque no doy con lo que me esta impidiendo la insercion de los datos en la base de datos. aqui les dejo el codigo y una muestra de como me sale el error no es descriptivo eso es printeo de los datos para ver que se leen bien y estan en correcta posicion para la insercion, el no ok es un testo que incluyo para saber si funciono o no si funciono debe ponerme ok y sino no ok por eso se que no me esta funcionando. Aqui les dejo el codigo y espero que me puedan ayudar como siempre lo hacen. Mil gracias de antemano.

Saludos Manuel Garcia.

:

Código PHP:
$userid $_SESSION['user_id'];
echo 
$_SESSION['cid'];
$date date('Y-m-d');

//check that the REQUEST_METHOD was sent
if($_SERVER['REQUEST_METHOD']=="POST"){
    
    
//$class_id = $_POST['cid'];
    
    
    
foreach($_POST as $id=>$value){
        
        
//check that id is not empty
        
         
if(!empty($id)){
             
             
//if id is numeric will execute the sql statement to insert the values for test into the database.
             
             
if(is_numeric($id)){
        
          
$mq 'INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")';
          
          
$r mysqli_query($dbc,$mq);
          
          
          echo 
mysqli_affected_rows($dbc);
          echo 
$mq;
          
           if(
$r){echo 'ok';}else {echo 'no ok';}
          
        
        }
        
         } else {
             
             echo 
"Please answer all the questions.";
         }
        
    }
    
//process the request done through the while and insert it into test.answers including the class_id, test_id and user_id that come from $_SESSION['user_id'];

}// end of $_SERVER['REQUEST_METHOD] IF.

//check that the student has not taken the exam yet.

/*"select * from test where user_id = ".$_SESSION['user_id'];
 * if !selection request for the date into class table else present 
 * a message that tells to the student that he has taken already the exam.
 */

$date date('Y-m-d');


$myq="SELECT * FROM class WHERE tdate ='".$date."'";

$q mysqli_query($dbc,$myq);


if(
mysqli_num_rows($q)!= 0){
    
    while(
$fila mysqli_fetch_array($q,MYSQLI_ASSOC)){
        
        
$class_id $fila['class_id'];
        
$_SESSION['cid'] = $class_id;
    } 
    
    
    
$tq "SELECT idq, question, a_a, a_b, a_c, a_d, class_id, chapter_id FROM questions WHERE class_id = $class_id AND active = 1 order by chapter_id ASC";
    
    
$rtq mysqli_query($dbc,$tq);
    
    

echo 
"<form action=\"index.php?p=takeit\" method=\"POST\" name id=\"\">";

 while(
$row mysqli_fetch_array($rtq,MYSQLI_ASSOC)){
     
    echo 
"<h3><b>".$row['question']."</b></h3>";
     echo 
"<h4><input type=\"radio\" name='".$row['idq']."' value=\"A\"> ".$row['a_a']."</h4>";
     echo 
"<h4><input type=\"radio\" name='".$row['idq']."' value=\"B\"> ".$row['a_b']."</h4>";
     echo 
"<h4><input type=\"radio\" name='".$row['idq']."' value=\"C\"> ".$row['a_c']."</h4>";
     echo 
"<h4><input type=\"radio\" name='".$row['idq']."' value=\"D\"> ".$row['a_d']."</h4>";
 }
 echo 
"<input type=\"submit\" name=\"mytest\" value=\"Send Test\">";
 echo 
"</form>";

} else {
    echo 
" <h1>Sorry: There is none test to take today.</h1>";
}

?> 
Cita:
Welcome Matilde Fonseca Log Out
1-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok-1INSERT INTO test (test_id, user_id, class_id, idq, asnwer, tdate) values (NULL, "$userid", "$_SESSION["id"]", "$id", "$value", "$date")no ok