You are here: MySQL Query « PHP SQL « IT news, forums, messages
MySQL Query

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация