954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

mysql_fetch_array warning urgent plz

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:

<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>


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.

oslover
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

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

DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD and DB_DATABASE

ultra vires
Junior Poster in Training
51 posts since Feb 2006
Reputation Points: 10
Solved Threads: 5
 

thanks but they are already defined.

oslover
Newbie Poster
2 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

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());
ultra vires
Junior Poster in Training
51 posts since Feb 2006
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You