title: How to pass a null value from HTML form to mysql db foreign key field
body: <p>I have two tables: parent and child. One of the child column references parent PRIMARY KEY with FOREIGN KEY constraint - child.parent_id references parent.parent_id. </p>
  
  <p>Foreign key column in child tables allows NULLs values because when child will be created parent may be not known yet. But when info about parent will be assigned/updated i want to have referential integrity. </p>
  
  <p>And now the question: </p>
  
  <p>How to pass null value from HTML form to MySQL? Quotes '' or "" not working "foreign key constraint fails" probably because it passes empty string instead of null value. Or maybe do I need to do some additional checking in PHP and convert it to null ?</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `parent` (
    `parent_id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(20) NOT NULL,
    `surname` varchar(20) NOT NULL,
    PRIMARY KEY (`parent_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  CREATE TABLE IF NOT EXISTS `child` (
   `child_id` int(11) NOT NULL AUTO_INCREMENT,
   `child_name` varchar(20) NOT NULL,
   `parent_id` int(11) DEFAULT NULL,
   PRIMARY KEY (`child_id`),
   KEY `fk_parent_id` (`parent_id`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  ALTER TABLE `child`
    ADD CONSTRAINT `fk_parent_id` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`parent_id`);
  </code></pre>