here is some sample code. if i have 2 correct answers out of 5. how should i grade it...
//check for incorrect posted answers?
if($POST['q1a] || $POST['q1c] || $POST['q1e] || $POST['q1d]){
$total=($total-1);
}
<?php
// Page Title
$title = "Preventing Medication Errors: Administering Drugs Safely";
// End Title
//who should get the results of the test?
$teacher_email = "user@duh.com";
// Correct answers possible
$possible = "10";
//
// Questions for test
//example
//$q1 = array('q'=>'1: Which patient factor influences the appearance of an ECG?',
//a => '<input name="q1a" type="checkbox" id="q1a" value="q1a"> A: Physical size',
//b => '<input name="q1b" type="checkbox" id="q1b" value="q1b"> B: Skin type',
//c => '<input name="q1c" type="checkbox" id="q1c" value="q1c"> C: Illness',
//d => '<input name="q1d" type="checkbox" id="q1d" value="q1d"> D: All of above',
//correct => '',
//);
$q1 = array('q'=>'1: The National Coordinating Council for Medication Error and Prevention has developed a comprehensive definition of medication error. A key component of this definition is that a medication error is:',
a => '<input name="q1a" type="checkbox" id="q1a" value="q1a"> A: preventable',
b => '<input name="q1b" type="checkbox" id="q1b" value="q1b"> B: committed only by healthcare providers',
c => '<input name="q1c" type="checkbox" id="q1c" value="q1c"> C: related solely to medication administration',
d => '<input name="q1d" type="checkbox" id="q1d" value="q1d"> D: caused by lack of knowledge',
correct => '',
);
$q2 = array('q'=>'2: Reported rates of medication error are generally considered to be very accurate for a given facility.',
a => '<input name="q2a" type="checkbox" id="q2a" value="q2a"> A: True',
b => '<input name="q2b" type="checkbox" id="q2b" value="q2b"> B: False',
//c => '<input name="q2c" type="checkbox" id="q2c" value="q2c"> C: Fragmin 5,000 units IV via heparin lock qd',
//d => '<input name="q2d" type="checkbox" id="q2d" value="q2d"> D: Heparin sodium 10,000 units IV via heparin lock q4h',
correct => '',
);
$q3 = array('q'=>'3: Which one of the following factors tends to cause a rise in the rate of medication errors?',
a => '<input name="q3a" type="checkbox" id="q3a" value="q3a"> A: decreased patient census',
b => '<input name="q3b" type="checkbox" id="q3b" value="q3b"> B: lower patient acuity',
c => '<input name="q3c" type="checkbox" id="q3c" value="q3c"> C: increasing numbers of new drugs',
d => '<input name="q3d" type="checkbox" id="q3d" value="q3d"> D: none of the above',
correct => '',
);
$q4 = array('q'=>'4: A nurse administers a dose of penicillin to a patient who has never had this drug before, and the patient develops no signs of allergic reaction. Therefore, the nurse can safely conclude that the patient will not have a reaction after future doses.',
a => '<input name="q4a" type="checkbox" id="q4a" value="q4a"> A: True',
b => '<input name="q4b" type="checkbox" id="q4b" value="q4b"> B: False',
//c => '<input name="q4c" type="checkbox" id="q4c" value="q4c"> C: complaint of incisional pain',
//d => '<input name="q4d" type="checkbox" id="q4d" value="q4d"> D: temperature 99.8 F',
correct => '',
);
// end qa arrays
// Check if answer is correct
if(isset($_POST['Submit'])){
include('checkme.php');
$total = $possible;
//YOU MUST EDIT THE $POST FIELDS!
if(!isset($POST['q1a'])){
$total=($total-1);
$message = "{$q1['q']}</br></br>";
}
if(!isset($_POST['q2b'])){
$total=($total-1);
$message = "{$q2['q']}</br></br>";
}
if(!isset($_POST['q3c'])){
$total=($total-1);
$message = "{$q3['q']}</br></br>";
}
if(!isset($_POST['q4b'])){
$total=($total-1);
$message = "{$q4['q']}</br></br>";
}
//**********************************************DO NOT EDIT PAST THIS MARK***************************************************************
//***************************************************************************************************************************************
$grade = ((100/$possible)*$total);
$grade = round($grade);
//show results page based on grade.
if($possible == $total){
$result = "You PASSED!! Good job, and have a great day!";
$email = "1";
$page = $_SERVER['HTTP_REFERER'];
header("Refresh: 5; url={$page}");
}
if($possible != $total){
$result = "<strong>Test Failed.</strong> Please re-take the exam until a passing score is achieved.</br></br><input type=\"submit\" onClick=\"goBack(1)\" value=\"Go Back\"></br>";
$page = $_SERVER['HTTP_REFERER'];
header("Refresh: 20; url={$page}");
}
// mail function
if($email == "1"){
$student_email = $_POST['student_email'];
$email_message_result = strip_tags($result);
$email_message .= strip_tags($message);
$headers = "From: ";
$today = date("F j, Y, g:i a");
$subject = "$title Submission from {$_POST['name']}";
$body = "
Test Date/Time: $today
Exam: $title
Name: {$_POST['name']}
Unit#: {$_POST['unit']}
Email: {$_POST['student_email']}
Clock#: {$_POST['clock#']}
Job Title: {$_POST['job_title']}
Nurse License#: {$_POST['nurse_license']}
******Total of $total out of $possible Correct******
Grade = {$grade}
$email_message_result
***********************************************************************************************
Any questions regarding the format of this exam should be forwarded to...
Attn:
";
mail($student_email,$subject,$body,$headers);
mail($teacher_email,$subject,$body,$headers);
}
echo "html page";
exit();
}
?>