I have problem with entering default values in MYSQL database. When i insert new record using phpmyadmin it works fine (empty fields get default value), but when i use the same query in my application (written in PHP), empty fields in html form don't get default value in MYSQL database. (I tried with NULL and NOT NULL attribute, but result is the same)
I know its beginners mistake but don't know how to solve this.
So, i have to check if there was some empty variable before calling function and exclude it, although this is a bit complicated because there should be many conditions then. Is there some solution better than this?
Actually, those variables already do have NULL value (defined in function definition: $email=null), just if I include them in mysql query, then in that field would not be default value, the field would stay blank.
You are mistaking the PHP function parameter for a MySQL input value.
If the PHP value for $email is null, than your query reads: insert into user (username, email) values('somename', ''); because PHP will replace the null value by an empty string.
If you change this query to insert into user (username, email) values('somename', NULL); the database field email will be set to NULL instead of ''.
That's what my str_replace(...) is for.