问题:尽管查询返回结果,但没有来自任何一个echo的输出,也没有发送任何电子邮件。
代码:
<?php
$link = mysqli_connect('localhost','USER','PASSWORD','MY-DB');
$result = mysqli_query($link, "'SELECT * FROM Current WHERE Status = 'IE-Window-Missing' order by location desc" );
$headers = 'From: SCS@cl.com' . "\r\n" .
'Reply-To: SCS@cl.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if($result->num_rows >= 1){
$email = "d@cl.com";
$subject = "One or more devices have IE windows missing";
$message='The following devices are having issues: "';
while($row=$result->fetch_assoc()) {
$message.="{$row['Location']}\r\n";
}
$message.="has been accepted for review at redacted.";
if(mail($email, $subject, $message, $headers)) {
echo "Winning";
//mail successfully sent
} else {
echo "fail";
}
}
?>
对DB进行直接的SQL查询会产生结果......这里出了什么问题?
谢谢,
答案 0 :(得分:1)
答案 1 :(得分:1)
$result = mysqli_query($link, "'SELECT * FROM Current WHERE Status = 'IE-Window-Missing' order by location desc" );
问题是你没有检查mysqli_query的返回值。你假设它正在发挥作用;并且所有echo
次来电都在if($result->num_rows >= 1){
支票内。因此,如果您的查询失败,它将不会达到任何一个。
实际问题是:
mysqli_query($link, "'SELECT *
^
您在SELECT查询的开头有一个额外的'
。这将生成一个无效的SQL字符串,这意味着查询失败;并且没有返回记录。
您应该使用mysqli_error
检查查询的回复,并做出适当的回应。