Whats wrong with this php code that exports mysql records to csv?
===

I have this bit of code on my file and its working well for a different file but on this new file which does the same thing with the one that works, it doesn't work 

    mysql_select_db($db);
    $result = mysql_query("SELECT CONCAT(employees.first_name, ' ' , employees.middle_name, ' ' , employees.last_name) AS fullname, banks.bank_code, bank_branch_code.branch_code, employees.account_number, pay_roll_history.payable, employees.email, banks.payment_type, banks.process_mode
    FROM employees,banks,bank_branch_code,pay_roll_history
    WHERE employees.bank_id = banks.bank_id
    AND employees.employee_id = pay_roll_history.employee_id
    AND banks.bank_id = bank_branch_code.bank_id
    AND pay_roll_history.payroll_date = '$this_date'");
	
	//Open a csv file
	$fp = fopen('c:\users\oteheddy\Desktop\test\BankReport.csv', 'w');
	
	
	//*************************************
	// fetch a row and write the column names out to the file
	$row = mysql_fetch_assoc($result);
	$line = "";
	$comma = "";
	
	foreach($row as $name => $value) {
		$line .= $comma . '"' . str_replace('"', '""', $name) . '"';
		$comma = ",";
	}
	$line .= "\n";
	fputs($fp, $line);
	
	// remove the result pointer back to the start
	mysql_data_seek($result, 0);
   



and i get these error



    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pitss\export\bankexport.php on line 32
    
    Warning: mysql_data_seek() [function.mysql-data-seek]: Offset 0 is invalid for MySQL result index 18 (or the query data is unbuffered) in C:\xampp\htdocs\pitss\export\bankexport.php on line 40



Pls what i'm i doing wrong?