Jump to content

Recommended Posts

I'd say it depends on what the field is.  For text fields like names, urls, emails, etc I generally just let it be an empty string and define the field not null.

 

If the field is storing an ID value which is a reference to another table, or a date/time value, I will set it to NULL when left empty, rather than use a value like 0 or something.

 

Link to comment
https://forums.phpfreaks.com/topic/265055-null-or/#findComment-1358204
Share on other sites

I'd say it depends on what the field is.  For text fields like names, urls, emails, etc I generally just let it be an empty string and define the field not null.

 

If the field is storing an ID value which is a reference to another table, or a date/time value, I will set it to NULL when left empty, rather than use a value like 0 or something.

 

Is it correct that an Input Field and text Area that are left blank will always result in an Empty String being assign to the $_POST?

 

 

Debbie

 

Link to comment
https://forums.phpfreaks.com/topic/265055-null-or/#findComment-1358211
Share on other sites

Make a form with all the types of fields, submit it and print_r() the $_POST array. Then you can see for yourself which fields do what when blank.

 

Well, I did that last night but just wanted some reassurance I was understanding things correctly, since I couldn't find any supporting info online.

 

But back to my OP, do you think I should leave Empty Strings as is, or convert them to NULLs?

 

It seems to me it would be better to convert things to NULL's, since that more accurately represents what an unanswered field really is.

 

Then again, a lot of people say that a table with a lot of NULL's in it is a sign of poor database design?!  :shrug:

 

The Form I am currently working on is User Details, so a lot of the fields are "optional"...

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/265055-null-or/#findComment-1358219
Share on other sites

But back to my OP, do you think I should leave Empty Strings as is, or convert them to NULLs?

 

It seems to me it would be better to convert things to NULL's, since that more accurately represents what an unanswered field really is.

 

Then again, a lot of people say that a table with a lot of NULL's in it is a sign of poor database design?!  :shrug:

 

The Form I am currently working on is User Details, so a lot of the fields are "optional"...

I'm afraid you are asking a very opinionated question here. It is really personal preference. As long as you're consistent on a per field basis, it really doesn't matter, IMHO.

 

If your scripts expect NULL, and are getting NULL from the database, it will work. If your scripts expect Empty Strings, and are getting Empty Strings from the database, it will work. If your scripts expect NULL, and get Empty Strings, or vice versa, you'll have issues.

Link to comment
https://forums.phpfreaks.com/topic/265055-null-or/#findComment-1358224
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.