title: PHP, pdo, how to insert NULL to mysql when the input is blank else the input value
body: <p>this is the table tbl_temp:</p>
  
  <pre><code>id(pri unique)      name(unique, null able)
  1                   abc
  2                   null
  3                   eadf
  4                   null
  5                   null 
  </code></pre>
  
  <p>this is the insert function:</p>
  
  <pre><code>$stmt = $this-&gt;conn-&gt;prepare("INSERT INTO tbl_temp (id, name) values (:id, :name);
  $stmt-&gt;bindParam(':id', $this-&gt;id, PDO::PARAM_INT);
  $stmt-&gt;bindParam(':name', $this-&gt;name);
  $stmt-&gt;execute();
  </code></pre>
  
  <p>this is the view for the insert function</p>
  
  <pre><code>&lt;from action='' method='post'&gt;
        &lt;input type='text' name='name'&gt;
        &lt;input type='submit' /&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>now here if the value is blank for the input name, it should assign the null to bindParam->name but it's assigning the value of 0 here which is giving error of duplicate if it give null then it will be ok because mysql can have null on unique but not zero</p>