Sketro Posted February 6, 2015 Share Posted February 6, 2015 (edited) Hello everyone. I have a problem with my php code, where I placed in hosting server. Everything works fine, my database,registration system(where I getting users names and emails to my database), even in this code, I'm recieving a message where I coded to message me that function "mail_body", is sent to the registered users(When I check registered user email, there is nothing(no email from this php system)). There are two problems , when I active this php file, I'm getting those two errors (below my text). If someone could help me, I would be truly grateful for such a help. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 6 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1848137/public_html/newsletter.php on line 8 <?php include_once "connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM newsletter WHERE received='0' LIMIT 20"); $numRows = mysql_num_rows($sql); $mail_body = ''; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $name = $row["name"]; $email = $row["email"]; $mail_body = '<html> <body style="background-color:#676666; font-family: Arial, Helvetica, sans-serif; line-height:1.8em;"> <h3 style="color:EE0000"><a href="http://pc123.com"><img src="img/baltas logo.png" alt="PC123.com" width="230" height="80" border="0"></a> Newsletter </h3> <p>Hi !' . $name . ',</p> <p>Text about something</p> <p>Testing</p> <hr> <p>u can refuse our <a href="/unregister/opt_out.php' . $email . '">clicking here</a> newsletter</p> </body> </html>'; $subject = "PC newsletter"; $headers = "From:PC123.com\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' WHERE email='$email' LIMIT 1"); } else { } } ?> <?php if ($numRows == 0) { $subj = "Newsletters had been sent"; $body = "Newsletters had been sent"; $hdr .= "Content-type: text/html\r\n"; mail("myemail@gmail.com", $subj, $body, $hdr); } ?> Edited February 7, 2015 by mac_gyver code tags around posted code please Quote Link to comment Share on other sites More sharing options...
CroNiX Posted February 6, 2015 Share Posted February 6, 2015 Well, don't assume your query actually runs before continuing on. See the very first example in the documentation for mysql_query() for how to detect query errors. Also notice the big pink notice at the top of the page that says that the mysql extension is deprecated and will be removed from PHP soon. Best not to use it if you want your code to run in the future. Quote Link to comment Share on other sites More sharing options...
Sketro Posted February 6, 2015 Author Share Posted February 6, 2015 Thanks fo the info u gave me, I truly appreciate it. Quote Link to comment Share on other sites More sharing options...
Tom10 Posted February 12, 2015 Share Posted February 12, 2015 Yeah like CroNiX said, before continuing on check the query has actually succeeded. if($sql === TRUE) { //Query was successful, Execute code } else { var_dump($sql); //The Query Failed, dump the data } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.