PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I get an error of Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/m/a/l/malikhaynes/html/mailtestmaillist2.php on line 13.
<?php
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
@MYSQL_CONNECT("localhost","root","1234");
@mysql_select_db("database");
$query = "SELECT FirstName, Email, FROM users WHERE id=$id";
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array($result))
{
$mailer = new FreakMailer();
// HTML body
$body = "Hello <font size=\"4\">" . $row["FirstName"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "PHPMailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["FirstName"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "PHPMailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["FirstName"]);
if(!$mail->Send())
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
$mysql=MYSQL_CONNECT("localhost","root","1234")
or die(mysql_error());
mysql_select_db("database", $mysql)
or die(mysql_error());
$query = "SELECT FirstName, Email, FROM users WHERE id=$id";
$result = MYSQL_QUERY($query, $mysql)
or die(mysql_error().': '.$query);
you are right! No $id. But where would that have been defined?
Error
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM users WHERE id=' at line 1: SELECT FirstName, Email, FROM users WHERE id=
Is this someone else's code you're using? It looks like it was written in the assumption that register_globals will be in in php.ini. Do you go to a URL like http://site.tld/script.php?id=xxx ? If you do then you need $_GET["id"] instead. Your script would therefore be vulnerable to SQL injection attacks.
<?php
// Grab our config settings
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
// Grab the FreakMailer class
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
$mysql=MYSQL_CONNECT("","","")
or die(mysql_error());
mysql_select_db("", $mysql)
or die(mysql_error());
$query = "SELECT FirstName, Email FROM users";
$result = MYSQL_QUERY($query, $mysql)
or die(mysql_error().': '.$query);
while ($row = mysql_fetch_array($result))
{
$mailer = new FreakMailer();
// HTML body
$body = "Hello <font size=\"4\">" . $row["FirstName"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "PHPMailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["FirstName"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "PHPMailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["Email"], $row["FirstName"]);
if(!$mail->Send())
echo "There has been a mail error sending to " . $row["Email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
d11wtq wrote:Is this someone else's code you're using? It looks like it was written in the assumption that register_globals will be in in php.ini. Do you go to a URL like http://site.tld/script.php?id=xxx ? If you do then you need $_GET["id"] instead. Your script would therefore be vulnerable to SQL injection attacks.
On a negative note, demonstrating code which requires register_globals to be on, and is also vulnerable to SQL injection is bad. However, I do belive that was not a copy & paste example... it's just a pseudo example to point you in the right direction.
cupaball wrote:Should I just use swiftmailer instead?
Unless you're happy using a library which ceased development in 2005, uses fairly amateur OOP and will not run in the latest versions of PHP without the error level turned down, then yes, it would probably be a good idea You'll get more support too since, well, I write it and I'm actually here But then I'm biased.
On a negative note, demonstrating code which requires register_globals to be on, and is also vulnerable to SQL injection is bad. However, I do belive that was not a copy & paste example... it's just a pseudo example to point you in the right direction.
cupaball wrote:Should I just use swiftmailer instead?
Unless you're happy using a library which ceased development in 2005, uses fairly amateur OOP and will not run in the latest versions of PHP without the error level turned down, then yes, it would probably be a good idea You'll get more support too since, well, I write it and I'm actually here But then I'm biased.
Swiftmailer it is!!!
Thanks for your help. I need to save you as a friend or something because I am sure I will need help with the mailing list from a databas part.