Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty string is not NOT NULL?

Status
Not open for further replies.

anulaibar

Programmer
Mar 1, 2003
17
0
0
SE
I'm trying to create a login system for my homepage and don't want the users to be able to submit empty fields in the form. I want to get an mysql error if someone tries to do it. But it doesn't seem to work although I've set the attributes of the table to be NOT NULL.

I get an mysql error if I submit 'null'(not a string), but not if I submit an empty string ''.

Can someone please help me!
Thanks!
 
Validate the fields before you pass them to mysql

if(empty($field)) {

// do sometging to make em fill it in

} ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
unless of sourse you are using ASP / CGI etc etc , then I guess post a simlir=ar question on the related forum. My bad, I what I posted above assumes use of PHP ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
This is ANSI standard SQL behaviour, NULL has a specific meaning, not the same as empty!

As the MySQL docs say ...

The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same thing as an empty string "". This is not the case! For example, the following statements are completely different:

mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ("");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top