session_start(); #GLOBAL CONSTANTS include("../mysql.php"); //include all mysql constants (abstracted for ease of migration) $nextQuestionURL = "question7.php"; //location of next question, tutorial, or end-of-test page. $flag=0; #ANSWER SUBMITTED -- Hanndles the case that this question has been answered. if(isset($_POST['answer6'])){ //Connect to db mysql_connect($mysqlURL,$mysqlUser,$mysqlPass); mysql_select_db($mysqlDatabase); //Question Update Database Queries -- $answerKey[questionNumber]=questionAnswer; $answerKey=array(); //create fresh array $answerKey[6]=$_POST['answer6']; $answerKey[7]=$_POST['answer7']; $answerKey[8]=$_POST['answer8']; $answerKey[9]=$_POST['answer9']; $answerKey[15]=$_POST['answer15']; #MYSQL -- This checks for existing answers in the database, then adds each of the student's answers. foreach($answerKey as $question=>$answer){ //Check the answer hasn't already been submitted. $testQuery=mysql_query("select count(id) as c from ".$mysqlAnswerTable." where sn=".$_SESSION['sn']." and question=".$question); if(mysql_error()){ echo "Please report this to the administrator: ".mysql_error(); die; } if(mysql_result($testQuery,0,'c')!=0) {mysql_close(); header("location:".$nextQuestionURL); die(); }; $query="insert into ".$mysqlAnswerTable."(sn,course,question,answer,tstamp) values('".mysql_escape_string($_SESSION['sn'])."','".mysql_escape_string($_SESSION['course'])."',".$question.",'".mysql_escape_string($answer)."',".time().")"; mysql_query($query); if(mysql_error()){ echo "Please report this to the administrator: ".mysql_error(); die; } } //Go to the next question. mysql_close(); header("location:".$nextQuestionURL); die(); } else if(isset($_POST['Submit'])) $flag=1; ?>