php - newsletter blast out script fail to blast out letter -
every time i'm try run script keep getting these error messages
(warning: mysql_num_rows(): supplied argument not valid mysql result resource in /home/a9016774/public_html/cronjob/blast_script.php on line 9)
and
(warning: mysql_fetch_array(): supplied argument not valid mysql result resource in /home/a9016774/public_html/cronjob/blast_script.php on line 21).
here code:
<?php /* ------------------------------------------------------------------- script written adam khoury @ www.developphp.com january 1, 2010 please retain credit when displaying code online ---------------------------------------------------------------------- */ include_once "../connect_to_mysql.php"; $sql = mysql_query("select * newsletter received='0' limit 20"); $numrows = mysql_num_rows($sql); // added "end campaign check" @ bottom of file(not shown on video) $mail_body = ''; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $email = $row["email"]; $name = $row["name"]; $mail_body = '<html> <body style="background-color:#ccc; color:#000; font-family: arial, helvetica, sans-serif; line-height:1.8em;"> <h3><a href="http://newsletter.netau.net/"><img src="http://www.yoursite.com/images/logo.png" alt="developphp" width="216" height="36" border="0"></a> newsletter </h3> <p>hello ' . $name . ',</p> <p>you can make out web page or design format require using html , css.</p> <p>~adam @ developphp</p> <hr> <p>to opt out of receiving newsletter, <a href="http://newsletter.netau.net/optout.php?e=' . $email . '">click here</a> , remove listing immediately.</p> </body> </html>'; $subject = "develop php newsletter"; $headers = "from:newsletter@newsletter.netau.net\r\n"; $headers .= "content-type: text/html\r\n"; $to = "$email"; $mail_result = mail($to, $subject, $mail_body, $headers); if ($mail_result) { mysql_query("update newsletter set received='1' email='$email' limit 1"); } else { // else statement can used write error log if mail function fails // can removed if not need error logging } } ?> <?php // section script discussed adding file on video // section sending site owner message informing them // people in database have been sent newsletter current campaign if ($numrows == 0) { // $numrows set on line 4 using existing query $subj = "newsletter campaign has ended"; $body = "the current newsletter campaign has ended. have been sent newsletter."; $hdr = "from:newsletter@newsletter.netau.net\r\n"; $hdr .= "content-type: text/html\r\n"; mail("austinbevon79@gmail.com", $subj, $body, $hdr); } // end check section ?>
please , thank you!
mysql_query
returns false
when error happens during execution of sql. , false
not mysql resource expected functions mysql_num_rows
, mysql_fetch_array
, , happens here. don't have necessary table newsletter
or table missing column received
.
you can check error adding
echo mysql_error($sql);
after line:
$sql = mysql_query("select * newsletter received='0' limit 20");
Comments
Post a Comment