jemmm Posted October 29, 2011 Share Posted October 29, 2011 Hi there, I am trying to allow users download a csv file from my website. This is the code I've been trying to use but it just opens a blank page and doesn't download anything. Any advice? <?php require_once (MYSQL); require_once ('mysqli_connect.php'); $q="SELECT * FROM table_name"; $r = @mysqli_query($dbc, $q); $html = "<table>"; $html .= "<tr><td>Song</td>"; $html .= "</tr>"; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $html .= "<tr><td>".$row['music_song']."</td>"; $html .= "</tr>"; } $html .= "</table>"; header("Content-Type: text/csv"); header("Content-Disposition: attachment;filename=yourfile.csv"); echo $html; ?> Link to comment Share on other sites More sharing options...
jemmm Posted October 29, 2011 Author Share Posted October 29, 2011 I've fixed it Link to comment Share on other sites More sharing options...
Larry Posted October 31, 2011 Share Posted October 31, 2011 Kudos for fixing it. In the future, could you post your fix/solution, too, so that others might benefit? And, per the forum rules, please include your details such as the PHP and MySQL version. Link to comment Share on other sites More sharing options...
Recommended Posts