title: Inserting PHP NULL variable value into MSSQL query
body: <p>I have this PHP IF statement that is working 'fine':</p>
  
  <pre><code>if(EMPTY($_POST['review_date'])){
      $review_date = NULL;
  }
  else {
      $review_date = $_POST['review_date'];
  }
  </code></pre>
  
  <p>The problem starts when I pass on the variable to the sqlsrv_query:  </p>
  
  <pre><code>sqlsrv_query($connect,"UPDATE goals SET review_date='$review_date' WHERE id='$department'") or die(sqlsrv_errors());
  </code></pre>
  
  <p>In the case where IF statement is TRUE, the value in the review_date cell shows up as 1900-01-01, instead of NULL.</p>
  
  <p>If I try to put quotes around the NULL value in the IF statement, I get the following error:</p>
  
  <blockquote>
    <p>Notice: Array to string conversion in
    C:\xampp\htdocs\project\edit.php on
    line 30</p>
  </blockquote>
  
  <p>If NULL is inserted into query directly, it executes as it should.</p>
  
  <p>The Column Properties in the goals Table have Allow Nulls enabled and Default Value is set to (NULL).</p>
  
  <p>Swifted through other questions but didn't really get anywhere.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>As requested, here is the HTML code:</p>
  
  <pre><code>&lt;form method="POST" action="edit.php"&gt;
  
  Review date &lt;i&gt;(optional)&lt;/i&gt;: &lt;input type="date" name="review_date" value="" placeholder="dd/mm/yyyy" &gt; 
  
  &lt;p&gt;&lt;button type="submit"&gt;Save&lt;/button&gt;&lt;/p&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>With regards to var_dumps:</p>
  
  <pre><code>var_dump($review_date);
  </code></pre>
  
  <p><strong>Returned:</strong> NULL</p>
  
  <pre><code>var_dump($department);
  </code></pre>
  
  <p><strong>Returned:</strong> string(2) "36" </p>
  
  <pre><code>var_dump(sqlsrv_query($connect,"UPDATE goals SET review_date='$review_date' WHERE id='$department'"));
  </code></pre>
  
  <p><strong>Returned:</strong> resource(7) of type (SQL Server Statement) </p>