I have mysql db with different tables. The data between the tables are linked and I retrieve and display them by using the userid. I used the reference from PHP MYS
mysql
Read the documentation
fputcsv should be array of values, you have a there string.