0

这是我的PHP:

#!/cron.php
<?php

$dbconnect = new mysqli('localhost','root','root','serrano');
$query = "SELECT `app`,`email`,`accept` FROM `requests` WHERE `accept`=1";

$result = mysql_query($query);

if($result && $result->num_rows>=1) {
    $subject = "Your application has been accepted for review.";
    $message='Congratulations. Your application "';

    while($row=$result->fetch_assoc()) {
        $message.="{$row['name']}\"";
        $email="{$row['email']}";
    }

    $message.="has been accepted for review at redacted.";
    if(mail($email, $subject, $message)) {
      //mail successfully sent
    } else {
        echo "fail";
    }
  }
?>

据我所知,查询工作正常。它返回数据库中的相关行。我的 PHP 怎么了?

代码更新 1

这是更新的 PHP,修正了 mysqli 错误。然而它仍然返回一个错误:

PHP 致命错误:在第 5 行 [...] 中的非对象上调用成员函数 query()

#!/cron.php
<?php

$dbconnect = new mysqli('localhost','root','root','serrano');
$result->query('SELECT `app`,`email`,`accept` FROM `requests` WHERE `accept`=1');

if($result && $result->num_rows>=1) {
$subject = "Your application has been accepted for review.";
$message='Congratulations. Your application "';

while($row=$result->fetch_assoc()) {
    $message.="{$row['name']}\"";
    $email="{$row['email']}";
}

$message.="has been accepted for review at redacted.";
if(mail($email, $subject, $message)) {
  //mail successfully sent
} else {
    echo "fail";
}
  }
?>

工作代码

好的,这是工作代码。只需对连接和运行查询的方式进行一些调整:

#!/cron.php
<?php


$link = mysqli_connect('localhost','root','root','serrano');

$result = mysqli_query($link, 'SELECT `app`,`email`,`accept` FROM `requests` WHERE  `accept`=1');

if($result->num_rows >= 1){
$subject = "Your application has been accepted for review.";
$message='Congratulations. Your application "';

while($row=$result->fetch_assoc()) {
    $message.="{$row['app']}\"";
    $email="{$row['email']}";
}

$message.="has been accepted for review at redacted.";
if(mail($email, $subject, $message)) {
  //mail successfully sent
} else {
    echo "fail";
}
 }
?>
4

1 回答 1

2

您正在使用mysqli,但同时使用mysql_query

它应该$dbconnect->query()代替mysql_query.

于 2012-06-30T15:45:36.260 回答