title: PHP MySQL Query
body: <p>I am having an issue with a SQL Query... I have a file that exports a CSV file which worked until i added a constraint to the query.</p>
  
  <p>Here is what i have </p>
  
  <pre><code>&lt;?php
   $today = date("mdY"); 
   function exportMysqlToCsv($table,$filename = 'TodaysSubmissions.csv')
   {
  $csv_terminated = "\n";
  $csv_separator = ",";
  $csv_enclosed = '"';
  $csv_escaped = "\\";
  $sql_query = "SELECT * FROM $table WHERE submitDate = '".$today."'";
  </code></pre>
  
  <p>I want to export all of the records from today only and in my form i am using the same date format for $today so it should match. </p>
  
  <p>Also when i change to this it creates the CSV file exactly the way that i want</p>
  
  <pre><code>$sql_query = "SELECT * FROM $table WHERE submitDate = 08142013";
  </code></pre>
  
  <p>So what am i doing wrong when i call $today in the query? I feel like i have tried this every possible way. </p>
  
  <p>Edit here is the entire file </p>
  
  <pre><code>            $today = date("mdY"); 
          function exportMysqlToCsv($table,$filename = 'TodaysSubmissions.csv')
          {
              $csv_terminated = "\n";
              $csv_separator = ",";
              $csv_enclosed = '"';
              $csv_escaped = "\\";
              $sql_query = 'SELECT * FROM $table WHERE submitDate = "'.$today.'"';
  
              // Gets the data from the database
              $result = mysql_query($sql_query);
              $fields_cnt = mysql_num_fields($result);
  
  
              $schema_insert = '';
  
              for ($i = 0; $i &lt; $fields_cnt; $i++)
              {
                  $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
                      stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
                  $schema_insert .= $l;
                  $schema_insert .= $csv_separator;
              } // end for
  
              $out = trim(substr($schema_insert, 0, -1));
              $out .= $csv_terminated;
  
              // Format the data
              while ($row = mysql_fetch_array($result))
              {
                  $schema_insert = '';
                  for ($j = 0; $j &lt; $fields_cnt; $j++)
                  {
                      if ($row[$j] == '0' || $row[$j] != '')
                      {
  
                          if ($csv_enclosed == '')
                          {
                              $schema_insert .= $row[$j];
                          } else
                          {
                              $schema_insert .= $csv_enclosed .
                              str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
                          }
                      } else
                      {
                          $schema_insert .= '';
                      }
  
                      if ($j &lt; $fields_cnt - 1)
                      {
                          $schema_insert .= $csv_separator;
                      }
                  } // end for
  
                  $out .= $schema_insert;
                  $out .= $csv_terminated;
              } // end while
  
              header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
              header("Content-Length: " . strlen($out));
              // Output to browser with appropriate mime type, you choose ;)
              header("Content-type: text/x-csv");
              //header("Content-type: text/csv");
              //header("Content-type: application/csv");
              header("Content-Disposition: attachment; filename=$filename");
              echo $out;
              exit;
  </code></pre>