2012-01-09 17 views
0

以下のスクリプトにいくつか問題があります。次の警告が表示されます。これはクエリの結果がnullであることを意味していますか?問題は、MySQLコンソールでコードクエリ自体を実行すると結果が返ってくるのですが?mysqlクエリから結果が返ってこない

$gasoil_daily_users = "SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'"; 
$result = mysql_query($gasoil_daily_users) or die(mysql_error()); 

あなたのコードが正常に動作する必要があります:あなたは、クエリ文字列に$gasoil_daily_usersを二行を削除、または変更した場合はmysql_query

$gasoil_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error()); 
$result = @MYSQL_QUERY($gasoil_daily_users); 

をINGの

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :  eval()'d code on line 53 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application \view.html.php(38) : eval()'d code on line 93 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :  eval()'d code on line 134 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :  eval()'d code on line 177 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :  eval()'d code on line 218 

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\server2go \server2go\htdocs\chandlers\components\com_jumi\views\application\view.html.php(38) :  eval()'d code on line 259 




    <?php     
     // SETS THE TIMEZONE TO UK TIME 
     date_default_timezone_set('Europe/London'); 

     // DEFINES WEEKDAY AND DAY OF THE MONTH 
     $weekday = date('D'); 
     $dayOfMonth = date('d'); 

     // RUNS THE EVERY DAY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY DAY 
     gasoildailyemailer(); 
     dervdailyemailer(); 
     kerodailyemailer(); 
     if ($weekday == 'Mon') 
     { 

     // RUNS THE WEEKLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY WEEK 
     gasoilweeklyemailer(); 
     dervweeklyemailer(); 
     keroweeklyemailer(); 
     if ($dayOfMonth <=6) { 

     // RUNS THE MONTHLY FUNCTIONS TO MAIL USERS IN THAT GROUP EVERY MONTH 
     gasoilmonthlyemailer(); 
     dervmonthlyemailer(); 
     keromonthlyemailer(); } 
     } 

     ?> 


    <?php 
    //start of gas oil daily emailer 
    function gasoildailyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test"; 

    $gasoil_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error()); 
    $result = @MYSQL_QUERY($gasoil_daily_users); 

    while ($row = mysql_fetch_array ($result)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    ?>  

    <?php 
    // START OF DERV DAILY EMAILER 
    function dervdailyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test"; 

    $derv_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'everyday'") or die(mysql_error()); 
    $result1 = @MYSQL_QUERY($derv_daily_users); 

    while ($row = mysql_fetch_array ($result1)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    // end of DERV daily emailer 
    ?>  

    <?php 
    //start of KERO daily emailer 
    function kerodailyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test"; 

    $kero_daily_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'everyday'") or die(mysql_error()); 
    $result2 = @MYSQL_QUERY($kero_daily_users); 

    while ($row = mysql_fetch_array ($result2)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    // end of KERO daily emailer 
    ?>  



    <?php 
    // start of GAS OIL WEEKLY emailer 
    function gasoilweeklyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test Weekly"; 

    $gasoil_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everymonday'") or die(mysql_error()); 
    $result3 = @MYSQL_QUERY($gasoil_every_mon_users); 

    while ($row = mysql_fetch_array ($result3)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    //end of GAS OIL WEEKLY emailer 
    ?>  

    <?php 
    // START OF DERV WEEKLY EMAILER 
    function dervweeklyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test Weekly"; 

    $derv_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'everymonday'") or die(mysql_error()); 
    $result4 = @MYSQL_QUERY($derv_every_mon_users); 

    while ($row = mysql_fetch_array ($result4)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    // END OF DERV WEEKLY EMAILER 
    ?>  

    <?php 
    // START OF KERO WEEKLY EMAILER 
    function keroweeklyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test Weekly"; 

    $kero_every_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'everymonday'") or die(mysql_error()); 
    $result5 = @MYSQL_QUERY($kero_every_mon_users); 

    while ($row = mysql_fetch_array ($result5)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    // END OF KERO WEEKLY EMAILER 
    ?>  



    <?php 
    // START OF GAS OIL MONTHLY EMAILER 
    function gasoilmonthlyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]uiseit.co.uk', 'List manager'); 

    $mail->Subject  = "Mailing List Test monthly"; 

    $gasoil_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'firstmondayofthemonth'") or die(mysql_error()); 
    $result6 = @MYSQL_QUERY($gasoil_1st_mon_users); 

    while ($row = mysql_fetch_array ($result6)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    // END OF GAS OIL MONTHLY EMAILER 
    ?>  

    <?php 
    //START OF DERV MONTHLY EMAILER 
    function dervmonthlyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test monthly"; 

    $derv_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivedervmailinglist = 'firstmondayofthemonth'") or die(mysql_error()); 
    $result7 = @MYSQL_QUERY($derv_1st_mon_users); 

    while ($row = mysql_fetch_array ($result7)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    //END OF DERV MONTHLY EMAILER 
    ?>  

    <?php 
    // START OF KERO MONTHLY EMAILER 
    function keromonthlyemailer(){ 
    require_once('./send/class.phpmailer.php'); 
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch 

    // $body    = file_get_contents('contents.html'); 

    $body = 'Dear Test this is a test.'; 

    // $body = preg_replace('/\\\\/i', $body); 

    $mail->SetFrom('[email protected]', 'List manager'); 
    $mail->AddReplyTo('[email protected]', 'List manager'); 

    $mail->Subject  = "Mailing List Test monthly"; 

    $kero_1st_mon_users = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivekeromailinglist = 'firstmondayofthemonth'") or die(mysql_error()); 
    $result8 = @MYSQL_QUERY($kero_1st_mon_users); 

    while ($row = mysql_fetch_array ($result8)) { 
     $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
     $mail->MsgHTML($body); 
     $mail->AddAddress($row["email"], $row["leadname"]); 
     $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); 

     if(!$mail->Send()) { 
     echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) . ') ' . $mail->ErrorInfo . '<br>'; 
     } else { 
     echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "&#64;", $row["email"]) . ')<br>'; 
     } 
     // Clear all addresses and attachments for next loop 
     $mail->ClearAddresses(); 
     $mail->ClearAttachments(); 
    } 
    }; 
    //END OF KERO MONTHLY EMAILER 
    ?>  
+0

どのクエリを?あなたが投稿したコードには複数のものがあります。あなたはそこに飛び込んであなたの質問に関係のないものを取り除くことができます - だれもコードの壁を歩き回るのは好きではありません。 – jprofitt

+0

mysql_query()を呼び出す前に、エラーが発生していないかどうかを確認するために、エラー押さえ演算子(@)を削除してみてください。 – jeanreis

+0

$ result = mysql_query(...)の行に気づいただけで、期待通りの結果が得られません(以前の結果を上書きしています)。 – jeanreis

答えて

1

あなたがいるmysql_query

+0

ahhhはい!ありがとう、愚かな間違いがあります。最初のクエリはもともと別のファイルにあったため、コピーしたときにクエリ部分を削除できなかったためです。 –

0

あなたはそれを間違った方法をやっている - の代わりに:

読み込みする必要があります。

$result = mysql_query("SELECT leadname , email FROM hqfjt_chronoforms_data_addupdatelead WHERE receivegasoilmailinglist = 'everyday'") or die(mysql_error()); 
while ($row = mysql_fetch_array ($result)) { 
... 

照会を再度照会する必要はありませんが、)

+0

テーブル名も確認してください。使用しているものは、テーブル名ではなく、外部の完全な名前(アカウント+テーブル名)のように疑わしく見えます。そして、あなたはどこか適切なデータベース接続と選択を行ったと思いますか?最後に、この作業が完了したら、MySQLiまたはPDOにアップデートすることを考えてください。 –

関連する問題