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
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