Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check code

Status
Not open for further replies.

riffy

Programmer
Mar 29, 2001
106
0
0
US
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


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 = &quot;SELECT * &quot;;
    $SQL2 .= &quot;FROM Users &quot;;
    $SQL2 .= &quot;WHERE Users.U_ID='&quot;.$U_ID.&quot;' &quot;;
    $result2 = MySQL_SubmitQuery($SQL2,$cnnDB);
    $row2 = mysql_fetch_array($result2);
    extract ($row2);
	
    echo (&quot;<p align=center>Thank you for taking all the quizzes. An email will be sent to you at &quot;[b].$row2['$U_email'].[/b]&quot; with all your scores.</p>&quot;);

    $SQL3 = &quot;SELECT * &quot;;
    $SQL3 .= &quot;FROM Results &quot;;
    $result3 = MySQL_SubmitQuery($SQL3,$cnnDB);
    $row3 = mysql_fetch_array($result3);
    extract ($row3);
    
    // E-mail Configuration
    $subject = &quot;Philips Lamp Facts Quizzes Completed&quot;;
    $from = &quot;webmaster@philipslighting.com&quot;;
    $from_name = &quot;Philips Lamp Facts&quot;;
    $to = $row2['$U_email'];
    $body = $row2['$U_nameFirst'].&quot; &quot;.$row2['$U_nameLast'].&quot; , has successfully completed all the Lamp Facts Quizzes.\n\nFor your records, the results of the quizzes are as follows:\n\n&quot;;
    $body .= &quot;Module &quot;.$row3['$M_ID'].&quot; - &quot;.$row3['$R_numCorrect'].&quot; out of &quot;.$row3['$R_numQuestions'];
    $MP = &quot;/usr/sbin/sendmail -t&quot;;
    $spec_envelope = 1;
    // Access Sendmail
    // Conditionally match envelope address
    if($spec_envelope) {
      $MP .= &quot; -f $from&quot;;
    }
    $fd = popen($MP,&quot;w&quot;);
    fputs($fd, &quot;To: $to\n&quot;);
    fputs($fd, &quot;From: $from_name <$from>\n&quot;);
    fputs($fd, &quot;Subject: $asubject\n&quot;);
    fputs($fd, &quot;X-Mailer: PHP3\n&quot;);
    fputs($fd, $body);
    pclose($fd);
  }
  else {
    echo (&quot;<p align=center>Please finish taking all the quizzes.</p>&quot;);
  }
}
 
yes i kind of figured that sleipnir

however everything works until the SQL2 statements
in the echo statement that follows that call to the database, the part when the U_email is being incorporated into the sentence doesn't seem to work at all...even though i have checked that U_email field exists in the Users table

after that nothing works, except for the last echo statement

arif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top