can someone please check this code and tell me if it's ok?
basically it's checking whether to send an email or not...
after the user is done taking all 9 quizzes, an email is sent listing the user's scores...however, in my code, the email is never sent, it's not even accessing the tables for some reason...it acknowledges that the quizzes have all been taken, however the email is not sent
thanks
arif
basically it's checking whether to send an email or not...
after the user is done taking all 9 quizzes, an email is sent listing the user's scores...however, in my code, the email is never sent, it's not even accessing the tables for some reason...it acknowledges that the quizzes have all been taken, however the email is not sent
thanks
arif
Code:
function Check_For_Email ($cnnDB, $U_ID, $M_ID) {
$SQL = "SELECT M_ID ";
$SQL .= "FROM Results ";
$SQL .= "WHERE Results.U_ID='".$U_ID."' ";
$result = MySQL_SubmitQuery($SQL,$cnnDB);
$i = 0;
$IDS = array();
while ($row = mysql_fetch_assoc($result)) {
$IDS[$i] = $row['M_ID'];
$i++;
}
$newlist = join(",", $IDS);
$SQL = "SELECT M_ID ";
$SQL .= "FROM Modules ";
$SQL .= "WHERE Modules.M_ID NOT IN ($newlist) ";
$result = MySQL_SubmitQuery($SQL,$cnnDB);
if (@mysql_num_rows($result) <= 0) {
$SQL2 = "SELECT * ";
$SQL2 .= "FROM Users ";
$SQL2 .= "WHERE Users.U_ID='".$U_ID."' ";
$result2 = MySQL_SubmitQuery($SQL2,$cnnDB);
$row2 = mysql_fetch_array($result2);
extract ($row2);
echo ("<p align=center>Thank you for taking all the quizzes. An email will be sent to you at "[b].$row2['$U_email'].[/b]" with all your scores.</p>");
$SQL3 = "SELECT * ";
$SQL3 .= "FROM Results ";
$result3 = MySQL_SubmitQuery($SQL3,$cnnDB);
$row3 = mysql_fetch_array($result3);
extract ($row3);
// E-mail Configuration
$subject = "Philips Lamp Facts Quizzes Completed";
$from = "webmaster@philipslighting.com";
$from_name = "Philips Lamp Facts";
$to = $row2['$U_email'];
$body = $row2['$U_nameFirst']." ".$row2['$U_nameLast']." , has successfully completed all the Lamp Facts Quizzes.\n\nFor your records, the results of the quizzes are as follows:\n\n";
$body .= "Module ".$row3['$M_ID']." - ".$row3['$R_numCorrect']." out of ".$row3['$R_numQuestions'];
$MP = "/usr/sbin/sendmail -t";
$spec_envelope = 1;
// Access Sendmail
// Conditionally match envelope address
if($spec_envelope) {
$MP .= " -f $from";
}
$fd = popen($MP,"w");
fputs($fd, "To: $to\n");
fputs($fd, "From: $from_name <$from>\n");
fputs($fd, "Subject: $asubject\n");
fputs($fd, "X-Mailer: PHP3\n");
fputs($fd, $body);
pclose($fd);
}
else {
echo ("<p align=center>Please finish taking all the quizzes.</p>");
}
}