Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql_fetch_array() not working [duplicate]

Tags:

php

email

mysql

Possible Duplicate:
PHP: mysql_fetch_array() expects parameter 1 to be resource, boolean given

I'm trying to send emails to addresses in a database. the addresses are in two parts: a username (aka 'number') and @something.com (aka 'carrier'). so the email address should be 'number' . 'carrier'

my code is below. the mail function works on its own (not in the loop). the error message i am getting is "mysql_fetch_array() expects parameter 1 to be resource, boolean given in home/username/public_html/script.php on line 15)

#!/usr/bin/php
<?
    require_once("PHPMailer/class.phpmailer.php");

    // connect to database
    mysql_connect("localhost", "username", "password");
    mysql_select_db("username_finalproject_Alerts");

    // prepare query
    $sql = "SELECT number, carrier FROM Alerts";
    // execute query
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result))
    {
        //generate email address
        $email = $row['number'] . $row['carrier'];

        // send mail

        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->Host = "private stmp address";
        $mail->ContentType = 'text/plain';
        $mail->IsHTML(false);
        $mail->SetFrom("private email address");
        $mail->AddAddress($email);
        $mail->Subject = "TRY 1";
        $mail->Body = "testing 1 2 3";
        if ($mail->Send() === false)
            die($mail->ErrorInfo . "\n");
    }

?>
like image 337
user1084785 Avatar asked Nov 19 '25 17:11

user1084785


1 Answers

There must be something wrong with your query, can you test it elsewere?

Perhaps you can try to catch the error

if(!$result) { echo mysql_error(); }

like image 92
Insecurefarm Avatar answered Nov 22 '25 09:11

Insecurefarm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!