aimmmmmmmmm aimmmmmmmmm - 1 year ago 97
MySQL Question

Sql Query Returns Object

$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;
$email = new PHPMailer();
$email->From = "";
$email->Subject = "$from";

When echoing $email, it returns the persons email address. However, when putting it in double quotes, I get an error message stating that an object cannot be converted into a string.

Thanks for your help,


Answer Source

Spot the problem:

retrieve the email:

        $email = $row["email"];

instantiate your mailer:

$email = new PHPMailer();
  ^---oops, now your database result is destroyed.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download