title: How to set a default value for empty/missing POST fields?
body: <p>I have a lot of <code>$_POST</code> elements and want to insert them into the database, but I must set a default value of &quot;NA&quot; when a user doesn't fill in the form.</p>
  <p>This my code:</p>
  <pre class="lang-php prettyprint-override"><code>$tgl_real   =  $_POST['TGL_REAL'];
  $rid        =  $_POST['RID'];
  $mesin      =  $_POST['MESIN'];
  $shift      =  $_POST['SHIFT'];
  $produk     =  $_POST['PRODUK'];
  $tanggal    =  $_POST['HT'];
  $no_aduk    =  $_POST['NO_ADUK'];
  $sho        =  $_POST['SHO'];
  $tb1        =  $_POST['TB1'];
  $gr1        =  $_POST['GR1'];
  $tb2        =  $_POST['TB2'];
  $gr2        =  $_POST['GR2'];
  $tb3        =  $_POST['TB3'];
  $gr3        =  $_POST['GR3'];
  $tb4        =  $_POST['TB4'];
  $gr4        =  $_POST['GR4'];
  $tb5        =  $_POST['TB5'];
  $gr5        =  $_POST['GR5'];
  $spr_besar  =  $_POST['SPR_BESAR'];
  $spr_kecil  =  $_POST['SPR_KECIL'];
  $br1        =  $_POST['BR1'];
  $br2        =  $_POST['BR2'];
  $br3        =  $_POST['BR3'];
  $tebal1     =  $_POST['TEBAL1'];
  $tebal2     =  $_POST['TEBAL2'];
  $tebal3     =  $_POST['TEBAL3'];
  $panjang    =  $_POST['PANJANG'];
  $lebar      =  $_POST['LEBAR'];
  $diameter   =  $_POST['DIAMETER'];
  $kc         =  $_POST['KC'];
  $kkc        =  $_POST['KKC'];
  $kerataaan_poles  = $_POST['KERATAAN_POLES'];
  
  $sql = &quot;INSERT INTO adonan SET `RID` = '$rid',
      `MESIN` = '$mesin',
      `SHIFT` = '$shift',
      `HARI_TGL` = '$tanggal',
      `TGL_REAL` = '$tgl_real',
      `PRODUK` = '$produk',
      `NO_ADUK` = '$no_aduk',
      `KERATAAN_SHO` = '$sho',
      `TEBAL_SHEET_GR1` = '$tb1',
      `KECAPATAN_KAIN_GR1` = '$gr1',
      `TEBAL_SHEET_GR2` = '$tb2',
      `KECAPATAN_KAIN_GR2` = '$gr2',
      `TEBAL_SHEET_GR3` = '$tb3',
      `KECAPATAN_KAIN_GR3` = '$gr3',
      `TEBAL_SHEET_GR4` = '$tb4',
      `KECAPATAN_KAIN_GR4` = '$gr4',
      `TEBAL_SHEET_GR5` = '$tb5',
      `KECAPATAN_KAIN_GR5` = '$gr5',
      `SPEED_ROLL_BESAR_WC` = '$spr_besar',
      `SPEED_ROLL_KECIL_WC` = '$spr_kecil',
      `BERAT1_ADONAN` = '$br1',
      `BERAT2_ADONAN` = '$br2',
      `BERAT3_ADONAN` = '$br3',
      `KETEBALAN1_ADONAN` = '$tebal1',
      `KETEBALAN2_ADONAN` = '$tebal2',
      `KETEBALAN3_ADONAN` = '$tebal3',
      `PANJANG_ADONAN` = '$panjang',
      `LEBAR_ADONAN` = '$lebar',
      `DIAMATER_ADONAN` = '$diameter',
      `MOLDER_SPEED` = '$kc',
      `KONVEYOR_SPEED` = '$kkc',
      `KERATAAN_POLES` = '$kerataaan_poles',
      `PROSENTASE_POLES` = '$prosentase_poles',
      `KERATAAN_GULA` = '$kerataaan_gula',
      `PROSENTASI_GULA` = '$kerataaan_gula'&quot;;
  </code></pre>
  <p>That $_POST is geting data from a form, but how do I set a default (&quot;NA&quot;) value
  in my database when a user doesn't fill in a value?</p>
  <p>I have tried to set a default value in my database, but it didn't work when a user doesn't fill in, my column field is still empty.</p>