title: How to set date in mysql to null and not to 0000-00-00
body: <p><a href="https://i.stack.imgur.com/xS27F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xS27F.png" alt="enter image description here"></a>I just finished a login-system and added another table for the useres personal information. For this reason, I have som inputs which aren't required. Textfields are nor problem but there is a problem with date and numberfields:
  Since the User isn't forced to give all the information fields that aren't filledin should be NULL. But in case of date it alway gives me 0000-00-00 instead and in case of number its always 0.</p>
  
  <p>I give you the whole code because I#m not sure about what is most important but I think its line 9, 10, 14-21, 73, 76</p>
  
  <pre><code>&lt;?php
  
    $user_id = $_GET['id'];
  
    if(isset($_POST['add-personal-data'])){
      $geschlecht = $_POST['geschlecht'];
      $vorname = $_POST['vorname'];
      $nachname = $_POST['nachname'];
      $alter = $_POST['alter'];
      $input_date = $_POST['geburtsdatum'];
      $lieblingsziel = $_POST['lieblingsziel'];
      $beschreibung = $_POST['beschreibung'];
  
      if($input_date != null){
        $geburtsdatum = date("Y-m-d H:i:s",strtotime($input_date));
      } else {
        $geburtsdatum = NULL;
      }
  
      $beschreibung_statement = $pdo-&gt;prepare("INSERT INTO beschreibung (user_id, name, vorname, geschlecht, user_alter, geburtsdatum, lieblingsziel, beschreibung)
                                              VALUES ('$user_id', '$nachname', '$vorname', '$geschlecht', '$alter', '$geburtsdatum', '$lieblingsziel', '$beschreibung')");
  
      $user_control_statement = $pdo-&gt;prepare("SELECT * FROM user WHERE user_id = '$user_id'");
      $user_control_statement-&gt;execute();
      $user = $user_control_statement-&gt;fetch();
  
      if($user != NULL){
  
          $user_has_description_statement = $pdo-&gt;prepare("SELECT * FROM beschreibung WHERE user_id = '$user_id'");
          $user_has_description_statement-&gt;execute();
          $description = $user_has_description_statement-&gt;fetch();
  
          if($description == NULL){
            $beschreibung_statement-&gt;execute();
          } else {
            echo ('&lt;div class="line fehler"&gt;&lt;p&gt; Dieser Benutzer besitzt bereits eine Beschreibung. &lt;/p&gt;&lt;/div&gt;');
          }
  
      } else {
        echo ('&lt;div class="line fehler"&gt;&lt;p&gt; Dieser Benutzer existiert nicht. &lt;/p&gt;&lt;/div&gt;');
      }
    }
  
      echo $geschlecht . "&lt;br&gt;" . $vorname . "&lt;br&gt;" . $nachname . "&lt;br&gt;" . $alter . "&lt;br&gt;" . $geburtsdatum . "&lt;br&gt;" . $lieblingsziel . "&lt;br&gt;" . $beschreibung ;
  
  ?&gt;
  &lt;main&gt;
    &lt;div class="line"&gt;
  
      &lt;div class="register"&gt;
  
        &lt;form method="post" action="?p=add-personal-data&amp;id=&lt;?php echo $user_id; ?&gt;"&gt;
  
          &lt;h2&gt;Persönliche Daten&lt;/h2&gt;
          &lt;hr /&gt;
          &lt;p&gt;Daten, die du hier angibst, werden auf deinem Profil angezeigt.&lt;/p&gt;
  
          &lt;h4&gt;Geschlecht&lt;/h4&gt;
          &lt;select name="geschlecht" class="datafield"&gt;
            &lt;option&gt;männlich&lt;/option&gt;
            &lt;option&gt;weiblich&lt;/option&gt;
            &lt;option&gt;anderes&lt;/option&gt;
            &lt;option selected&gt;keine Angabe&lt;/option&gt;
          &lt;/select&gt;
  
          &lt;h4&gt;Vorname&lt;/h4&gt;
          &lt;input type="text" name="vorname" placeholder="Vorname" class="datafield" value=""&gt;
  
          &lt;h4&gt;Nachname&lt;/h4&gt;
          &lt;input type="text" name="nachname" placeholder="Nachname" class="datafield" value=""&gt;
  
          &lt;h4&gt;Alter&lt;/h4&gt;
          &lt;input type="number" name="alter" placeholder="Alter" class="datafield" value=""&gt;
  
          &lt;h4&gt;Geburtsdatum&lt;/h4&gt;
          &lt;input type="date" name="geburtsdatum" placeholder="Geburtsdatum" class="datafield" value=""&gt;
  
          &lt;h4&gt;Lieblingsziel&lt;/h4&gt;
          &lt;input type="text" name="lieblingsziel" placeholder="Lieblingsziel" class="datafield" value=""&gt;
  
          &lt;h4&gt;Beschreibung&lt;/h4&gt;
          &lt;textarea name="beschreibung" wrap="soft" class="datafield" rows="5" placeholder="Gib hier persönliche information, wie zum Beispiel Hobbies an."&gt;&lt;/textarea&gt;
  
          &lt;div&gt;
            &lt;input type="submit" name="add-personal-data" value="Speichern" class="submitbutton"&gt;
          &lt;/div&gt;
  
        &lt;/form&gt;
      &lt;/div&gt;
  
    &lt;/div&gt;
  &lt;/main&gt;
  
  </code></pre>
  
  <p>How can I set NULL to "geburtsdatum" and "user_alter" if the user doesn't give any information?</p>