SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can not null field be null???

    I am using a php script to enter data into a database. I have set some of the fields in the database as not null. However when I leave the fields blank in my php form and click submit it doesnt return me an error and the item is added with a blank value in the corresponding field.

    I am wondering what not null mean if it can accept null values. How do I overcome this problem.

    Thanks for the help

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Null is a perfectly valid value... (Interesting comment...) You can chack the value of your fields against "" to see if it has a null value.
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  3. #3
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will be a tedious job since i have lot of fields all of which will have to be checked.

    Any easier solution?

    I cant understand that if the field can take null values whats the point of defining them as "not null". What is this attribute meant to do?

  4. #4
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do it via javascript, I believe there is a 'foreach' type of command. Javascript handles the form as a great big object so it is very easy to manipulate, just play around with javascript.
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  5. #5
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I could do that.

    But still I need to know out of curiousity whats the use of the not null attribute. If I can get it do what I think it should do it will be much easier.

    One of the advantage would be that I am adding the data through lot of forms spread under various categories. Hence all of the forms will have to be accompanied by the javascript validation script. But if the database stops accepting null values somehow I will not need to put so many scripts all through my website hence save have a smaller and neater code.

    Any help would be appreciated.

    Thanks

  6. #6
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if a column is created with the null flag, the values can be null, if it flagged as not null, then a default value is put in if no value is inserted. For int, the default is 0, for dates 00-00-0000, for text "", and so forth...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  7. #7
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really need to get a solution to this. Anyone???

  8. #8
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So it there a way to force the database to not accept null/default values.

  9. #9
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. You have to check it before you send to the DB... you have to accept the fact that is good programming habit to do the testing/manipulation yourself and then send it to the DB, this way, you know exactly what is happening...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  10. #10
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... so I guess I will have to do the Javascript validation on all pages. That will be some work!!

    Thanks for the help anyways.

  11. #11
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't forget PHP's wonderful power of server side includes...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  12. #12
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a little clearer.



    What was trying to be got at is this


    the fields set to "not null" are doing just that. However, you can't see that because you see that you are instering no value and no value is coming up. But that isn't true. What is showing up in those fields is this


    ""


    That isn't null. Wierd, but true. So if you want those fields to automatically have a entry, you have to set them not "Not Null" and make the defualt "balh blah blah".


    Make more sense?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  13. #13
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    server side includes of php are great but there is no master javascript script which i can attach to all the pages since all pages(forms) have different number of fields and input types for which javascript will have to be made individually.

    I will get started with that boring stuff tommorrow.

    I still dont understand whats the difference between null and "". Very weird.

  14. #14
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's something



    When you think of a vaccum (as in space) there is NOTHING. It is NULL nothing at all exists in it.

    However when you think of AIR you think of something that is there but that you can't perceive.

    That's sorta how NULL and "" work. NULL means absolutely no value, nothing. Where as "" means, i have no true value, but i exist.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  15. #15
    SitePoint Enthusiast tipiyanos's Avatar
    Join Date
    Jun 2001
    Location
    NY, New York
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Milamber
    i have no true value, but i exist.
    Sounds strange but makes sense. Anyways, I wont crack my head on that anymore and go on with my project. I will just remember
    null=vacuum and ""=air

    Thanks for the help.
    Have a great day.

  16. #16
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In relational databases you have three value logic: TRUE, FALSE and NULL ("unknown"). Think of NULL as "unknown". It is actually an important concept that is necessary when creating complex joins on tables such as outer joins. I love this topic Here are some of the threads that have discussed the idea of NULL in MySQL and in PHP in the past:

    NULL and three value logic (and the necessity of NULL for outer joins)
    http://www.sitepointforums.com/showt...highlight=NULL

    Testing for NULL in PHP:
    http://www.sitepointforums.com/showt...highlight=NULL
    http://www.sitepointforums.com/showt...highlight=NULL


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •