abs0lut Posted August 13, 2008 Share Posted August 13, 2008 I have a form with a text field. If a user types "0", I want to insert "0" into my mysql database. If a user leaves the field blank, I want to insert NULL into the database. However, my code keeps inserting "0" into my database even when the field is left blank. could you please help me? Link to comment https://forums.phpfreaks.com/topic/119576-zero-and-null/ Share on other sites More sharing options...
unkwntech Posted August 13, 2008 Share Posted August 13, 2008 Could you post some code. I can't tell you if there is an error with your eval, without seeing code. Link to comment https://forums.phpfreaks.com/topic/119576-zero-and-null/#findComment-616062 Share on other sites More sharing options...
jipo Posted August 14, 2008 Share Posted August 14, 2008 I have a form with a text field. If a user types "0", I want to insert "0" into my mysql database. If a user leaves the field blank, I want to insert NULL into the database. However, my code keeps inserting "0" into my database even when the field is left blank. could you please help me? you can use if statement like : if ($_GET['txt1']=""){ $sql="INSERT INTO db values (null)" } else $sql="INSERT INTO db values('".$_GET['txt1']."') Link to comment https://forums.phpfreaks.com/topic/119576-zero-and-null/#findComment-616188 Share on other sites More sharing options...
toplay Posted August 14, 2008 Share Posted August 14, 2008 The column in the table must also be defined as having NULL. In the create table definition, if neither NULL nor NOT NULL is specified, the column is treated as though NULL had been specified. Link to comment https://forums.phpfreaks.com/topic/119576-zero-and-null/#findComment-616202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.