duandao1931 2013-09-03 14:37
浏览 25

PHP代码 - 返回错误[关闭]

I am trying to automate an email alert after checking a sql query first.

As I am not so familiar with php I found a code for that purpose however there is row 29 that returns me an error.

   while($row = mysqli_fetch_array($result))
  {
  $message = {$row['User Name'] . " " . $row['Email']. " " . $row['Course']. " " .      $row['Attempt']. " " . $row['Grade']. " " . $row['Finish time']
};
  }

Please advise. You can find below all the code. Thank you.

<?php
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT
us.username AS 'User Name',
us.email AS 'Email',
qu.name AS 'Course',
quat.attempt AS 'Attempt',
quat.sumgrades AS 'Grade',
FROM_UNIXTIME(quat.timefinish,'%M %D %Y %h:%i:%s') AS 'Finish time'
FROM mdl_quiz_attempts AS quat
JOIN mdl_user AS us ON quat.userid=us.id
JOIN mdl_quiz AS qu ON quat.quiz=qu.id
WHERE (quat.attempt = 3 OR quat.attempt = 6) AND quat.sumgrades < 80 AND quat.timefinish > (unix_timestamp(now())-300)
ORDER BY us.username,qu.name,quat.attempt");

if($result->num_rows>=1) {
   $email='dc@antaea.com';
   $subject = "E-School failed attempts";
   $message='One or more users failed quiz three or more times:

';

   while($row = mysqli_fetch_array($result))
  {
  $message = {$row['User Name'] . " " . $row['Email']. " " . $row['Course']. " " . $row['Attempt']. " " . $row['Grade']. " " . $row['Finish time']
};
  }

  if(mail($email, $subject, $message)) {
      //mail successfully sent
   } else {
      //mail unsuccessful
   }
}

mysqli_close($con);
?>
  • 写回答

1条回答 默认 最新

  • dongyi2425 2013-09-03 14:39
    关注

    Try with that (with the as a string at the end):

       while($row = mysqli_fetch_array($result)){
      $message = {$row['User Name'] . " " . $row['Email']. " " . $row['Course']. " " .      $row['Attempt']. " " . $row['Grade']. " " . $row['Finish time'] . "
    "};
      }
    

    Escaped characters can not use with single quote, you must double Single quote for this like " "

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)