<?php

function mailOut($to, $from, $from_name, $subject, $body)
{
	//echo "entered";


	require("class.phpmailer.php");

		//echo "entered2";
	
	$mail = new PHPMailer();

	$mail->IsSMTP(true);                                      // set mailer to use SMTP
	$mail->Host = "smtp.gmail.com";  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = "realcompemail@gmail.com";  // SMTP username
    $mail->Password = "BrentAnos7282!!"; // SMTP password
	$mail->SMTPSecure = "ssl"; // secure transfer enabled REQUIRED for GMail
	$mail->SMTPDebug = 1;
	$mail->Port = 465;


	$mail->From = $from; //
	$mail->FromName = $from_name; //
	
	 
	$pieces = explode(";", $to);
	
	foreach ($pieces as &$value) 
	{
		if (strlen($value) != 0)
			$mail->AddAddress($value, $value);
	}
	
	
	//$mail->AddAddress($to, $to); // this should be the user's email address
	
	
	//$mail->AddBCC("jocc@hotmail.com"); // this should be the office email address

	$mail->WordWrap = 100;                                 // set word wrap to 50 characters
	//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
	//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
	$mail->IsHTML(true);                                  // set email format to HTML

	$mail->Subject = $subject; //"Here is the subject";
	$mail->isHTML(true);
	$mail->Body    = $body; //"This is the HTML message body <b>in bold!</b>";
	//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

		//echo "entered3";
	
	if(!$mail->Send())
	{
		//echo "Message could not be sent. <p>";
		//echo "Mailer Error: " . $mail->ErrorInfo;
		//exit;
	}

	//echo "Message has been sent";

}

Function make($total)
{	$con = mysql_connect('localhost', 'root', 'Boom95z') or die(mysql_error());								mysql_select_db('cgg_web', $con);									$result_1 = mysql_query("select qid, textis from questions");	while($row = mysql_fetch_array($result_1)){	if ($row['qid'] == '1')		$q1	= $row['textis'];	if ($row['qid'] == '2')		$q2	= $row['textis'];	if ($row['qid'] == '3')		$q3	= $row['textis'];	if ($row['qid'] == '4')		$q4	= $row['textis'];	if ($row['qid'] == '5')		$q5	= $row['textis'];		if ($row['qid'] == '6')		$q6	= $row['textis'];	if ($row['qid'] == '7')		$q7	= $row['textis'];	if ($row['qid'] == '8')		$q8	= $row['textis'];	if ($row['qid'] == '9')		$q9	= $row['textis'];	if ($row['qid'] == '10')		$q10	= $row['textis'];			if ($row['qid'] == '11')		$q11	= $row['textis'];			if ($row['qid'] == '12')		$q12	= $row['textis'];			if ($row['qid'] == '13')		$q13	= $row['textis'];			if ($row['qid'] == '14')		$q14	= $row['textis'];			if ($row['qid'] == '15')		$q15	= $row['textis'];			if ($row['qid'] == '16')		$q16	= $row['textis'];			if ($row['qid'] == '17')		$q17	= $row['textis'];		if ($row['qid'] == '18')		$q18	= $row['textis'];		if ($row['qid'] == '19')		$q19	= $row['textis'];		if ($row['qid'] == '20')		$q20	= $row['textis'];		if ($row['qid'] == '21')		$q21	= $row['textis'];		if ($row['qid'] == '22')		$q22	= $row['textis'];		if ($row['qid'] == '23')		$q23	= $row['textis'];		if ($row['qid'] == '24')		$q24	= $row['textis'];		if ($row['qid'] == '25')		$q25	= $row['textis'];		}			$result_2 = mysql_query("select qid, ans_bullet from answers where correct=1");	while($row = mysql_fetch_array($result_2)){	if ($row['qid'] == '1')		if ($_POST['rd_1'] != $row['ans_bullet'])  $err_1 = ' WRONG '; else $err_1 = '';	if ($row['qid'] == '2')		if ($_POST['rd_2'] != $row['ans_bullet'])  $err_2 = ' WRONG '; else $err_2 = '';			if ($row['qid'] == '3')		if ($_POST['rd_3'] != $row['ans_bullet'])  $err_3 = ' WRONG '; else $err_3 = '';			if ($row['qid'] == '4')		if ($_POST['rd_4'] != $row['ans_bullet'])  $err_4 = ' WRONG '; else $err_4 = '';if ($row['qid'] == '5')		if ($_POST['rd_5'] != $row['ans_bullet'])  $err_5 = ' WRONG '; else $err_5 = '';	if ($row['qid'] == '6')		if ($_POST['rd_6'] != $row['ans_bullet'])  $err_6 = ' WRONG '; else $err_6 = '';	if ($row['qid'] == '7')		if ($_POST['rd_7'] != $row['ans_bullet'])  $err_7 = ' WRONG '; else $err_7 = '';	if ($row['qid'] == '8')		if ($_POST['rd_8'] != $row['ans_bullet'])  $err_8 = ' WRONG '; else $err_8 = '';	if ($row['qid'] == '9')		if ($_POST['rd_9'] != $row['ans_bullet'])  $err_9 = ' WRONG '; else $err_9 = '';	if ($row['qid'] == '10')		if ($_POST['rd_10'] != $row['ans_bullet'])  $err_10 = ' WRONG '; else $err_10 = '';	if ($row['qid'] == '11')		if ($_POST['rd_11'] != $row['ans_bullet'])  $err_11 = ' WRONG '; else $err_11 = '';	if ($row['qid'] == '12')		if ($_POST['rd_12'] != $row['ans_bullet'])  $err_12 = ' WRONG '; else $err_12 = '';	if ($row['qid'] == '13')		if ($_POST['rd_13'] != $row['ans_bullet'])  $err_13 = ' WRONG '; else $err_13 = '';		if ($row['qid'] == '14')		if ($_POST['rd_`4'] != $row['ans_bullet'])  $err_14 = ' WRONG '; else $err_14 = '';	if ($row['qid'] == '15')		if ($_POST['rd_15'] != $row['ans_bullet'])  $err_15 = ' WRONG '; else $err_15 = '';	if ($row['qid'] == '16')		if ($_POST['rd_16'] != $row['ans_bullet'])  $err_16 = ' WRONG '; else $err_16 = '';	if ($row['qid'] == '17')		if ($_POST['rd_17'] != $row['ans_bullet'])  $err_17 = ' WRONG '; else $err_17 = '';	if ($row['qid'] == '18')		if ($_POST['rd_18'] != $row['ans_bullet'])  $err_18 = ' WRONG '; else $err_18 = '';	if ($row['qid'] == '19')		if ($_POST['rd_19'] != $row['ans_bullet'])  $err_19 = ' WRONG '; else $err_19 = '';if ($row['qid'] == '20')		if ($_POST['20'] != $row['ans_bullet'])  $err_20 = ' WRONG '; else $err_20 = '';			if ($row['qid'] == '21')		if ($_POST['rd_21'] != $row['ans_bullet'])  $err_21 = ' WRONG '; else $err_21 = '';			if ($row['qid'] == '22')		if ($_POST['rd_22'] != $row['ans_bullet'])  $err_22 = ' WRONG '; else $err_22 = '';			if ($row['qid'] == '23')		if ($_POST['rd_23'] != $row['ans_bullet'])  $err_23 = ' WRONG '; else $err_23 = '';			if ($row['qid'] == '24')		if ($_POST['rd_24'] != $row['ans_bullet'])  $err_24 = ' WRONG '; else $err_24 = '';			if ($row['qid'] == '25')		if ($_POST['rd_25'] != $row['ans_bullet'])  $err_25 = ' WRONG '; else $err_25 = '';		}
	$ret =  "<html>".
			"<body>" . 
			"<span font=\"Arial\" color=\"gray\">" .
			"<b>Name:</b> " .  mysql_escape_string($_POST['f1']) . "<br/><br/>" .			"<p><b>Result:</b>" . $total . "/25"  . "</p><br/><br/>" .						
			"<b>" . $q1 . "</b> " . $_POST['rd_1'] . " - " . $err_1 . "<br/><br/>" ."<b>" . $q2 . "</b>: " . $_POST['rd_2'] . " - " . $err_2 . "<br/><br/>" ."<b>" . $q3 . "</b>: " . $_POST['rd_3'] . " - " . $err_3 . "<br/><br/>" ."<b>" . $q4 . "</b>: " . $_POST['rd_4'] . " - " . $err_4 . "<br/><br/>" ."<b>" . $q5 . "</b>: " . $_POST['rd_5'] . " - " . $err_5 . "<br/><br/>" ."<b>" . $q6 . "</b>: " . $_POST['rd_6'] . " - " . $err_6 . "<br/><br/>" ."<b>" . $q7 . "</b>: " . $_POST['rd_7'] . " - " . $err_7 . "<br/><br/>" ."<b>" . $q8 . "</b>: " . $_POST['rd_8'] . " - " . $err_8 . "<br/><br/>" ."<b>" . $q9 . "</b>: " . $_POST['rd_9'] . " - " . $err_9 . "<br/><br/>" ."<b>" . $q10 . "</b>: " . $_POST['rd_10'] . " - " . $err_10 . "<br/><br/>" ."<b>" . $q11 . "</b>: " . $_POST['rd_11'] . " - " . $err_11 . "<br/><br/>" ."<b>" . $q12 . "</b>: " . $_POST['rd_12'] . " - " . $err_12 . "<br/><br/>" ."<b>" . $q13 . "</b>: " . $_POST['rd_13'] . " - " . $err_13 . "<br/><br/>" ."<b>" . $q14 . "</b>: " . $_POST['rd_14'] . " - " . $err_14 . "<br/><br/>" ."<b>" . $q15 . "</b>: " . $_POST['rd_15'] . " - " . $err_15 . "<br/><br/>" ."<b>" . $q16 . "</b>: " . $_POST['rd_16'] . " - " . $err_16 . "<br/><br/>" ."<b>" . $q17 . "</b>: " . $_POST['rd_17'] . " - " . $err_17 . "<br/><br/>" ."<b>" . $q18 . "</b>: " . $_POST['rd_18'] . " - " . $err_18 . "<br/><br/>" ."<b>" . $q19 . "</b>: " . $_POST['rd_19'] . " - " . $err_19 . "<br/><br/>" .
"<b>" . $q20 . "</b>: " . $_POST['rd_20'] . " - " . $err_20 . "<br/><br/>" ."<b>" . $q21 . "</b>: " . $_POST['rd_21'] . " - " . $err_21 . "<br/><br/>" ."<b>" . $q22 . "</b>: " . $_POST['rd_22'] . " - " . $err_22 . "<br/><br/>" ."<b>" . $q23 . "</b>: " . $_POST['rd_23'] . " - " . $err_23 . "<br/><br/>" ."<b>" . $q24 . "</b>:: " . $_POST['rd_24'] . " - " . $err_24 . "<br/><br/>" ."<b>" . $q25 . "</b> " . $_POST['rd_25'] . " - " . $err_25 . "<br/><br/>" .												
			"</p>" .
			"</span>" .
			"</body>" .
			"</html>"; 
			
	return $ret;
	 
	
	
}
$con = mysql_connect('localhost', 'root', 'Boom95z') or die(mysql_error());								mysql_select_db('cgg_web', $con);
$f1= mysql_escape_string($_POST['f1']);
  
$rd_1 = $_POST['rd_1']; $rd_2 = $_POST['rd_2']; $rd_3 = $_POST['rd_3']; $rd_4 = $_POST['rd_4']; $rd_5 = $_POST['rd_5']; $rd_6 = $_POST['rd_6']; $rd_7 = $_POST['rd_7']; $rd_8 = $_POST['rd_8']; $rd_9 = $_POST['rd_9']; $rd_10 = $_POST['rd_10']; $rd_11 = $_POST['rd_11']; $rd_12 = $_POST['rd_12']; $rd_13 = $_POST['rd_13']; $rd_14 = $_POST['rd_14']; $rd_15 = $_POST['rd_15']; $rd_16 = $_POST['rd_16']; $rd_17 = $_POST['rd_17']; $rd_18 = $_POST['rd_18']; $rd_19 = $_POST['rd_19']; $rd_20 = $_POST['rd_20']; $rd_21 = $_POST['rd_21']; $rd_22 = $_POST['rd_22']; $rd_23 = $_POST['rd_23']; $rd_24 = $_POST['rd_24']; $rd_25 = $_POST['rd_25']; mysql_query("insert into exam (username,datesubmitted,ans1  ,ans2  ,ans3  ,ans4  ,ans5  ,ans6  ,ans7  ,ans8  ,ans9  ,ans10  ,ans11  ,ans12  ,ans13  ,ans14  ,ans15  ,ans16  ,ans17  ,ans18  ,ans19  ,ans20  ,ans21  ,ans22  ,ans23, ans24, ans25) values ('" . $f1 . "',now()," ."'" . $rd_1 . "'," ."'" . $rd_2 . "'," ."'" . $rd_3 . "'," ."'" . $rd_4 . "'," ."'" . $rd_5 . "'," ."'" . $rd_6 . "'," ."'" . $rd_7 . "'," ."'" . $rd_8 . "'," ."'" . $rd_9 . "'," ."'" . $rd_10 . "'," ."'" . $rd_11 . "'," ."'" . $rd_12 . "'," ."'" . $rd_13 . "'," ."'" . $rd_14 . "'," ."'" . $rd_15 . "'," ."'" . $rd_16 . "'," ."'" . $rd_17 . "'," ."'" . $rd_18 . "'," ."'" . $rd_19 . "'," ."'" . $rd_20 . "'," ."'" . $rd_21 . "'," ."'" . $rd_22 . "'," ."'" . $rd_23 . "'," ."'" . $rd_24 . "'," ."'" . $rd_25 . "')");$total = 0;$result_1 = mysql_query("select ans_bullet from answers where qid='1' and correct=1");while($row = mysql_fetch_array($result_1)) { if ($row['ans_bullet'] == $rd_1) {$total++;echo "found<br/>";}; };$result_2 = mysql_query("select ans_bullet from answers where qid='2' and correct=1");while($row = mysql_fetch_array($result_2)) { if ($row['ans_bullet'] == $rd_2) {$total++;echo "found<br/>";}; }$result_3 = mysql_query("select ans_bullet from answers where qid='3' and correct=1");while($row = mysql_fetch_array($result_3)) { if ($row['ans_bullet'] == $rd_3) {$total++;echo "found<br/>";}; }$result_4 = mysql_query("select ans_bullet from answers where qid='4' and correct=1");while($row = mysql_fetch_array($result_4)) { if ($row['ans_bullet'] == $rd_4) {$total++;echo "found<br/>";}; }$result_5 = mysql_query("select ans_bullet from answers where qid='5' and correct=1");while($row = mysql_fetch_array($result_5)) { if ($row['ans_bullet'] == $rd_5) {$total++;echo "found<br/>";}; }$result_6 = mysql_query("select ans_bullet from answers where qid='6' and correct=1");while($row = mysql_fetch_array($result_6)) { if ($row['ans_bullet'] == $rd_6) {$total++;echo "found<br/>";}; }$result_7 = mysql_query("select ans_bullet from answers where qid='7' and correct=1");while($row = mysql_fetch_array($result_7)) { if ($row['ans_bullet'] == $rd_7) {$total++;echo "found<br/>";}; }$result_8 = mysql_query("select ans_bullet from answers where qid='8' and correct=1");while($row = mysql_fetch_array($result_8)) { if ($row['ans_bullet'] == $rd_8) {$total++;echo "found<br/>";}; }$result_9 = mysql_query("select ans_bullet from answers where qid='9' and correct=1");while($row = mysql_fetch_array($result_9)) { if ($row['ans_bullet'] == $rd_9) {$total++;echo "found<br/>";}; }$result_10 = mysql_query("select ans_bullet from answers where qid='10' and correct=1");while($row = mysql_fetch_array($result_10)) { if ($row['ans_bullet'] == $rd_10) {$total++;echo "found<br/>";}; }$result_11 = mysql_query("select ans_bullet from answers where qid='11' and correct=1");while($row = mysql_fetch_array($result_11)) { if ($row['ans_bullet'] == $rd_11) {$total++;echo "found<br/>";}; }$result_12 = mysql_query("select ans_bullet from answers where qid='12' and correct=1");while($row = mysql_fetch_array($result_12)) { if ($row['ans_bullet'] == $rd_12) {$total++;echo "found<br/>";}; }$result_13 = mysql_query("select ans_bullet from answers where qid='13' and correct=1");while($row = mysql_fetch_array($result_13)) { if ($row['ans_bullet'] == $rd_13) {$total++;echo "found<br/>";}; }$result_14 = mysql_query("select ans_bullet from answers where qid='14' and correct=1");while($row = mysql_fetch_array($result_14)) { if ($row['ans_bullet'] == $rd_14) {$total++;echo "found<br/>";}; }$result_15 = mysql_query("select ans_bullet from answers where qid='15' and correct=1");while($row = mysql_fetch_array($result_15)) { if ($row['ans_bullet'] == $rd_15) {$total++;echo "found<br/>";}; }$result_16 = mysql_query("select ans_bullet from answers where qid='16' and correct=1");while($row = mysql_fetch_array($result_16)) { if ($row['ans_bullet'] == $rd_16) {$total++;echo "found<br/>";}; }$result_17 = mysql_query("select ans_bullet from answers where qid='17' and correct=1");while($row = mysql_fetch_array($result_17)) { if ($row['ans_bullet'] == $rd_17) {$total++;echo "found<br/>";}; }$result_18 = mysql_query("select ans_bullet from answers where qid='18' and correct=1");while($row = mysql_fetch_array($result_18)) { if ($row['ans_bullet'] == $rd_18) {$total++;echo "found<br/>";}; }$result_19 = mysql_query("select ans_bullet from answers where qid='19' and correct=1");while($row = mysql_fetch_array($result_19)) { if ($row['ans_bullet'] == $rd_19) {$total++;echo "found<br/>";}; }$result_20 = mysql_query("select ans_bullet from answers where qid='20' and correct=1");while($row = mysql_fetch_array($result_20)) { if ($row['ans_bullet'] == $rd_20) {$total++;echo "found<br/>";}; }$result_21 = mysql_query("select ans_bullet from answers where qid='21' and correct=1");while($row = mysql_fetch_array($result_21)) { if ($row['ans_bullet'] == $rd_21) {$total++;echo "found<br/>";}; }$result_22 = mysql_query("select ans_bullet from answers where qid='22' and correct=1");while($row = mysql_fetch_array($result_22)) { if ($row['ans_bullet'] == $rd_22) {$total++;echo "found<br/>";}; }$result_23 = mysql_query("select ans_bullet from answers where qid='23' and correct=1");while($row = mysql_fetch_array($result_23)) { if ($row['ans_bullet'] == $rd_23) {$total++;echo "found<br/>";}; }$result_24 = mysql_query("select ans_bullet from answers where qid='24' and correct=1");while($row = mysql_fetch_array($result_24)) { if ($row['ans_bullet'] == $rd_24) {$total++;echo "found<br/>";}; }$result_25 = mysql_query("select ans_bullet from answers where qid='25' and correct=1");while($row = mysql_fetch_array($result_25)) { if ($row['ans_bullet'] == $rd_25) {$total++;echo "found<br/>";}; }echo $total ;
mailOut("johnm@genteq.com.au", "Quiz Result", "Quiz Result", "Quiz Result", make($total));
mysql_close($con);
//header("Location: quiz.php?rt=1#ll");

?>
