php - Sql 查询返回对象

标签 php mysql

$sql = "SELECT email FROM users WHERE username='$User'";
    $result = $conn->query($sql);
    if($result->num_rows > 0){
        while($row = $result->fetch_assoc()){
            $email = $row["email"];
        }
    }
    echo $email;
    require_once("class.phpmailer.php");;
    $email = new PHPMailer();
    $email->From = "clientinformation@apbdispatch.com";
    $email->Subject = "$from";
    $email->AddAddress("$email");

当回显 $email 时,它会返回此人的电子邮件地址。但是,当将其放在双引号中时,我收到一条错误消息,指出对象无法转换为字符串。

感谢您的帮助,

目标mmmmmmmm

最佳答案

发现问题:

检索电子邮件:

        $email = $row["email"];

实例化您的邮件程序:

$email = new PHPMailer();
  ^---oops, now your database result is destroyed.

关于php - Sql 查询返回对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39107439/

相关文章:

PHP MYSQL 查询在 PHP 中不起作用,但在 PHPMyAdmin 中起作用

JavaScript 计时器不适用于多个实例

php - POST undefined variable ,但 REQUEST 有效

php - 指定源语言,如果 default_locale 不是英语

Mysql Date 在 where 子句中?

javascript - 无法使用nodejs连接到mysql

PHP filter_var_array() 只检查一个值是否为真?

python - 当列为varchar时,django从mysql中选择最大字段

mysql - JSON 字符串 - 在 MySQL 数据库中包含单引号

mysql - 如何使用 XML_LOAD() 将 XML 文件导入 MySQL 数据库表;功能