morocco-iceberg Posted July 13, 2010 Share Posted July 13, 2010 I'm only new to this and am getting a bit stuck. Basically function sent() outputs a set of questions within a form, the user answers the questions and function mark() is supposed to check whether the user got the answers correct. The output of sent() is a group of dropdown boxes that thes user has to construct a sentence from. The dropboxes contain preset words. My attempt at mark() is below, with the relevant code from sent() below that. The specific error that I am receiving says "Notice: Undefined variable:" and then lists all of the letters. How can I fix it/make it better/do it another way? function mark($table){ $counter = 0; while($counter<2){ $id = $_POST[$table."_q".$counter]; $sql = mysql_query("SELECT * FROM $table WHERE id = '{$id}'") or die($error); $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"); foreach($letters as $number => $letter){ ${'a'.$letter} = $_POST[$table."_a".$number]; while($row = mysql_fetch_array($sql)){ ${$letter} = $row[$letter]; } ${'c'.$letter} = strcmp(${'a'.$letter}, ${$letter}); } if ($ca == 0 && $cb == 0 && $cc == 0 && $cd == 0 && $ce == 0 && $cf == 0 && $cg == 0 && $ch == 0 && $ci == 0 && $cj == 0 && $ck == 0 && $cl == 0 && $cm == 0 && $cn == 0 && $co == 0 && $cp == 0 && $cq == 0 && $cr == 0 && $cs == 0 && $ct == 0){ global $score; $score++; }else{ global $score; $score = $score; } $counter++; } } function sent($table){ $sql = mysql_query("SELECT * FROM $table ORDER BY RAND()") or die($error); $counter = 0; while($row = mysql_fetch_array($sql)){ $id[$counter] = $row["id"]; $a[$counter] = $row["a"]; $b[$counter] = $row["b"]; $c[$counter] = $row["c"]; $d[$counter] = $row["d"]; $e[$counter] = $row["e"]; $f[$counter] = $row["f"]; $g[$counter] = $row["g"]; $h[$counter] = $row["h"]; $i[$counter] = $row["i"]; $j[$counter] = $row["j"]; $k[$counter] = $row["k"]; $l[$counter] = $row["l"]; $m[$counter] = $row["m"]; $n[$counter] = $row["n"]; $o[$counter] = $row["o"]; $p[$counter] = $row["p"]; $q[$counter] = $row["q"]; $r[$counter] = $row["r"]; $s[$counter] = $row["s"]; $t[$counter] = $row["t"]; $counter++; } $counter = 0; while($counter<2){ echo "<input type=\"hidden\" name=\"".$table."_q".$counter."\" value=\"".$id[$counter]."\">"; ${$table.'_a'.$counter} = array("$a[$counter]", "$b[$counter]", "$c[$counter]", "$d[$counter]", "$e[$counter]", "$f[$counter]", "$g[$counter]", "$h[$counter]", "$i[$counter]", "$j[$counter]", "$k[$counter]", "$l[$counter]", "$m[$counter]", "$n[$counter]", "$o[$counter]", "$p[$counter]", "$q[$counter]", "$r[$counter]", "$s[$counter]", "$t[$counter]"); ${$table.'_c'.$counter} = ${$table.'_a'.$counter}; shuffle(${$table.'_a'.$counter}); $number = 0; echo "<table border=\"1\" bordercolor=\"#000000\" rules=\"none\" frame=\"box\" cellpadding=\"5\"><tr>"; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<td>".${$table.'_a'.$counter}[$number]."</td>"; } $number++; } echo "</tr></table><br/><table><tr>"; foreach(${$table.'_c'.$counter} as $column){ if(empty($column)){ break; }else{ echo "<td><select name=\"".$table."_a".$counter."\"><option value=\"0\"></option>"; $number = 0; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<option value=\"".${$table.'_a'.$counter}[$number]."_".$number."\">".${$table.'_a'.$counter}[$number]."</option>"; } $number++; } echo "</select></td>"; } } echo "</tr></table><br/>"; $counter++; } } Link to comment https://forums.phpfreaks.com/topic/207599-marking-function-for-an-online-exam-not-working/ Share on other sites More sharing options...
kenrbnsn Posted July 13, 2010 Share Posted July 13, 2010 Please tell use the exact error and which line it's referring to. Ken Link to comment https://forums.phpfreaks.com/topic/207599-marking-function-for-an-online-exam-not-working/#findComment-1085316 Share on other sites More sharing options...
morocco-iceberg Posted July 13, 2010 Author Share Posted July 13, 2010 Notice: Undefined variable: b on line 48 (minus the 36 lines not included means line 12 in the code I've provided). Notice: Undefined index: sente_a2 on line 44 (line 10) Notice: Undefined variable: c on line 48 Notice: Undefined index: sente_a3 on line 44 And it just goes on and on like that for each letter and number. Link to comment https://forums.phpfreaks.com/topic/207599-marking-function-for-an-online-exam-not-working/#findComment-1085320 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.