|
Posted by Dave Thomas on 08/29/05 18:24
If I have a table set up like this:
Name | VARCHAR
Email | VARCHAR
Age | TINYINT | NULL (Default: NULL)
And I want the user to enter his or her name, email, and age - but AGE
is optional.
My insert would look something like:
INSERT INTO data (Name, Email, Age) VALUES ('$name', '$email', $age)
This is all good, except if the user doesn't enter an age. Then $age is
an empty variable. I thought that since the table is set up where Age
can be NULL, that this should be fine. But MySQL is giving me an error.
If $age is a number, it is no problem.
Anyway to make it accept $age as an empty variable (and just make it
NULL)? I know I could say:
if (empty($age)) { $age = 0; }
and write it that way, but this is just an example and there are many
more variables that could be empty.
Thanks.
Navigation:
[Reply to this message]
|