Entering NULL from a form
am 23.02.2006 18:43:04 von Bob Sanderson
I have a date field in my database which is set to accept NULLs. If I enter
a record from phpMyAdmin and leave the date field blank, the record is
entered properly. However, if I do the same thing from a form, I get an
error that the date cannot be blank. It seems that I need to enter a NULL
in the date field from the form rather that nothing. How do I do this?
Re: Entering NULL from a form
am 23.02.2006 19:09:47 von avidfan
Bob Sanderson wrote:
> I have a date field in my database which is set to accept NULLs. If I enter
> a record from phpMyAdmin and leave the date field blank, the record is
> entered properly. However, if I do the same thing from a form, I get an
> error that the date cannot be blank. It seems that I need to enter a NULL
> in the date field from the form rather that nothing. How do I do this?
check to see
if ($date === '' or !isset($date)) $date='NULL';
or something similar. Depending on the usage of this date field, if a
null value is passed I would set it using a default value.
alter table tablename modify (datecolumn not null default
current_timestamp);
You will have to check the exact syntax, but this is close...
Re: Entering NULL from a form
am 27.02.2006 18:09:43 von Bob Sanderson
noone wrote in
news:LTmLf.34223$Jd.6715@newssvr25.news.prodigy.net:
> Bob Sanderson wrote:
>> I have a date field in my database which is set to accept NULLs. If I
>> enter a record from phpMyAdmin and leave the date field blank, the
>> record is entered properly. However, if I do the same thing from a
>> form, I get an error that the date cannot be blank. It seems that I
>> need to enter a NULL in the date field from the form rather that
>> nothing. How do I do this?
>
>
> check to see
> if ($date === '' or !isset($date)) $date='NULL';
This almost works, but the resultant statement contains the single
quotation marks, which cause an error.
INSERT INTO jobs ( JobNumber, DateRcvd, DateEff ) VALUES ( '9999', 'NULL',
'NULL')
Does not work, but
INSERT INTO jobs ( JobNumber, DateRcvd, DateEff ) VALUES ( '9999', NULL,
NULL)
does.
How can I remove the qoutes?