title: MySQLi Storing date values
body: <p>I have a MySQL table with a field that is date format and can be NULL.</p>
  <p>I'm updating an old PHP update file to use mysqli prepared statements and having problems saving date field values to the DB resulting in</p>
  <blockquote>
  <p>Fatal error: Uncaught mysqli_sql_exception: Incorrect date value:.....</p>
  </blockquote>
  <p>Minimum reproducible code below:</p>
  <pre><code>&lt;?php
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); //force detailed report and die
  
  require_once('../Connections/mysqli_connect.php');
  
  //---------------------------on submit, do ------------------------------------
  
  if ((isset($_POST[&quot;update&quot;])) &amp;&amp; ( $_POST[&quot;update&quot;] == &quot;editnoteform&quot;)) {
      
      //Prepare dates
      if(!isset($_POST['forecastdate'])){
          $forecastdate = NULL;
      } else {
          $forecastdate = $_POST['forecastdate'];
      }
      
      //---------------------------update record ------------------------------------
      
      $record_update = mysqli_prepare($conn, &quot;UPDATE CONTNOTES SET FORECASTDATE=? WHERE NOTESID=?&quot;);
      mysqli_stmt_bind_param($record_update, &quot;di&quot;, 
          $_POST['forecastdate'],
          $_POST['notesid']
      );// bind parameters
      mysqli_stmt_execute($record_update);// execute query
  
  }
  
  //---------------------------get existing data------------------------------------
  
  $rs_notes = mysqli_prepare($conn, &quot;SELECT NOTESID, FORECASTDATE FROM CONTNOTES WHERE NOTESID = ?&quot;);
  mysqli_stmt_bind_param($rs_notes, &quot;i&quot;, $_GET['NOTESID']);// bind parameters
  mysqli_stmt_execute($rs_notes);// execute query
  mysqli_stmt_bind_result($rs_notes, $NOTESID, $FORECASTDATE);// bind result variables
  
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;/&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;?php while (mysqli_stmt_fetch($rs_notes)) {?&gt;
  
          &lt;form class=&quot;prompts&quot; action=&quot;&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot; name=&quot;editnoteform&quot; id=&quot;editnoteform&quot; onSubmit=&quot;&quot;&gt;
  
              &lt;input class=&quot;prompt&quot; type=&quot;date&quot; name=&quot;forecastdate&quot; id=&quot;forecastdate&quot; value=&quot;&lt;?php if($FORECASTDATE &lt;&gt; NULL){echo date(&quot;Y-m-d&quot;,strtotime($FORECASTDATE));} ?&gt;&quot;&gt;
  
              &lt;input type=&quot;hidden&quot; name=&quot;notesid&quot;  id=&quot;notesid&quot; value=&quot;&lt;?php echo $NOTESID; ?&gt;&quot;&gt;
              &lt;input type=&quot;hidden&quot; name=&quot;update&quot; value=&quot;editnoteform&quot;&gt;
  
              &lt;input class=&quot;button&quot; name=&quot;submit&quot; id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Update&quot;&gt;
  
          &lt;/form&gt;
  
      &lt;?php } ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php
  mysqli_stmt_close($rs_notes);
  mysqli_close ($conn);
  ?&gt;
  </code></pre>
  <p>How is this an incorrect date value if the html field is a &quot;date&quot; type?</p>