title: Submit SQL data to CSV file using PHP
body: <p>Hi I am trying to submit msSQL data to create a csv file using PHP; however, when I click submit the csv file is never created. I am wondering if it has something to do with the way I am reading from my database. But I am new to php and sql programming and I am lost as to what is going wrong. Also I have no errors. My code is below.</p>
  
  <pre><code>&lt;p&gt;
  &lt;input name="submit" class="submit" type="submit" value="SUBMIT" /&gt;
  &lt;/p&gt;
  &lt;?php
    if(isset($_POST['submit']))
    {
        $db = get_db_connection('swcrc');
        $db-&gt;connect();
  
        $filename = 'uploads/'.strtotime("now").'.csv';
  
        $fp = fopen($filename,"w");
  
        $db-&gt;query("SELECT [request_ID], [user_ID], [complete], [comment], [response_date], [animalClass], [animalCommon], [bioSurveyStatus]  FROM dbo.Response");
        $num_rows = mysql_num_rows($db);
  
          $row = mysql_fetch_assoc($db);
          $seperator = "";
          $comma = "";
  
          foreach($row as $name =&gt; $value)
          {
              $seperator .= $comma . '' .str_replace('','""',$name);
              $comma = ",";
          }
          $seperator = "\n";
  
          echo $seperator;
  
          fputs($fp,$seperator);
  
          mysql_data_seek($db,0);
  
          while($row = mysql_fetch_assoc($db))
          {
          $seperator = "";
          $comma = "";
  
          foreach($row as $name =&gt; $value)
          {
              $seperator .= $comma . '' .str_replace('','""',$value);
              $comma = ",";
          }
          $seperator = "\n";
          fputs($fp,$seperator);
          }
  
  
          fclose($fp);
    }
  
  ?&gt;
  </code></pre>
  
  <p>Thank you for the help and looking.</p>
  
  <p><img src="https://i.stack.imgur.com/IUDe4.jpg" alt="These are the errors I am receiving when hitting submit"></p>