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.

Recommended Answers

All 3 Replies

you have to define these variables before you can use them.

DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD and DB_DATABASE

thanks but they are already defined.

Are you using PHP version > 4.0.6 ??

Version Description
4.0.6 This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.

Example :

$db_name="rps";
$db_url="localhost";
$db_username="root";
$db_password="rps";
$connection = mysql_connect($db_url,$db_username,$db_password);
mysql_select_db($db_name,$connection);

$results = mysql_query("SELECT * FROM abcd;",$connection) or die("Couldn?t execute query." . mysql_error());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.