Insert Empty String Instead of NULL

Using PHP and MySQL
I do not do a lot of custom inserting. I have a form and am using Dreamweaver CS5 to insert the form variables into a MySql table. Some of the form fields are optional. When I test this form and do not fill out a field, I get a Column 'colName' cannot be null.

I could I guess easily enough mark each of my columns with a default value of NULL but I'm afraid that when the table results are printed it will show NULL for that empty field.

How can I get form variables that do not have a value to show as an empty string in the database?
LVL 16
Who is Participating?
Cornelia YoderArtistCommented:
Why don't you try setting one field to NULL and see if it prints "NULL" or nothing.  That's the easy way to check.  You can always change it right back.

I believe (without setting up a test), that a field with null value will show nothing.  
Lukasz ChmielewskiCommented:
or setting any of these optional as value="" will give you a NOT NULL but an empty value.
rbudjAuthor Commented:
I would have just given each input a value="" so it would input empty string but I am using validation so the value is populated.

yodercm, I may have to setup a test form for this. Will take me a bit. My other form is 6 pages long with 100 database rows. You can imagine the nightmare testing can be. I'll report back.

I just figured there was a common function for this.
rbudjAuthor Commented:
Thanks for the answers. Again, I use WebAssist and when form data that is uploaded that is null, it just inserts an empty string in the database. Which is MUCH better than looking at a bunch of NULL's. Just thought there was a function or something to take care of this. I created a test form and the null column field does not disply the word NULL so this is good. I can work with it until I figure this out. Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.