[UPHPU] SQL problem

Mac Newbold mac at macnewbold.com
Tue Oct 12 16:51:08 MDT 2004


Today at 1:34pm, District Webmaster said:

>00:00:00 is the default value for a TIME field -- not NULL.

I can't confirm or deny the above, but there may also be something else at
work here:

>  INSERT INTO tblSchedule
>                 (userid,
>                  Monday_start,
>                  Monday_end)
>                  VALUES
>                  ('$userid',
>                  '$Monday_start',
>                  '$Monday_end')
>
>>From what I understand, if $Monday_end is an empty variable, or
>doesn't exist, then MySQL will set Monday_end to it's default( NULL in
>this case).   But what is happening is that MySQL is putting in
>00:00:00 instead of NULL.  Is this happening because $Monday_end is in
>the query? Do have I have to remove $Monday_end from the query if it
>is unset and I want it's default value in MySQL ?
>
>I've tried sending "NULL" if the variable isn't set, but that doesn't
>seem to work either.

As you suspected, it may have to do with what you're sending. When
$Monday_end is empty, you end up sending something like this:

  INSERT INTO tblSchedule
                 (userid,
                  Monday_start,
                  Monday_end)
                  VALUES
                  ('myuserid',
                  '',
                  '')

The important thing to note here is that NULL is different than emtpy
string. 'NULL' is also different than NULL. I think the way to set a null
is like this:

insert into tblSchedule (userid,Monday_start,Monday_end) values
('myuserid',NULL,NULL);

Of course, modulo all that by what Webmaster Dave said above.

Mac

--
Mac Newbold		MNE - Mac Newbold Enterprises, LLC
mac at macnewbold.com	http://www.macnewbold.com/



More information about the UPHPU mailing list