The first requirement is to configure your table to store nulls. But you know, letting null to store into your database table is not advisable. It's not that because it's bad or something, they are actually built for a reason but handling null requires a bit of special handling hence it's a more complex to handle at some point and situations that's why some devs or db admins avoid them in a well designed and normalized schema. By the way, in .Net we store null using the literal 'null' keyword. I dont know how to do that in php. And your code? wow! I miss those coding scheme back in college. That's the most vulnerable way of dealing with database(You didnt even use parameterized sql command strings). Avoid using sql text commands. It's prone in injection tricks. Use Stored Procedures, Triggers instead or you might want to learn using O/RM like Entity framwork or NHibernate. It doesnt bother you now because it's just for academic purposes but in production? man! you might be fired by your project head. haha! Using Stored proc or O/RM promotes maintainability, security, cleaner code, etc. utilize it's advantage, learn using it and thank me later.