Hi i am new here and I post this topic hoping that i will get some urgent help. I tried this code which should work to export customers emails according to their orders' status but the exported file contained an error.
This is the error:
PHP Code:
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/var/www/vhosts/site.com/httpdocs/admin/email_export.php</b> on line <b>37</b><br />
line 37 is : while ( $row = mysql_fetch_array($result)) {
and this is all the file code:
<?php
$filename="addresses.txt"; //.txt is good for import into excel workbook as tab delimited file
// end of configuration!
require('includes/application_top.php'); // gives us SOME security anyway
require_once('includes/configure.php'); // gives us osC database info
header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) {
$sql = "SELECT customers_firstname, customers_lastname, customers_email_address FROM customers c, orders o WHERE c.customers_id = o.customers_id and orders_status = 2";
$result = mysql_db_query ( DB_DATABASE , $sql );
echo "email\tFirst Name\tLast Name\n";
while ( $row = mysql_fetch_array($result)) {
if ($row[customers_email_address]) {
echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n";
}
}
}
mysql_close ();
?>
Looking forward to your kind replies.