diode Posted November 3, 2006 Share Posted November 3, 2006 These are the fields that are in my table, 'users'.acctno int AUTO_INCREMENT NOT NULL,firstname varchar(30) NOT NULL,lastname varchar(30) NOT NULL,acctname varchar(30) NOT NULL,email varchar(30) NOT NULL,datecreated date NOT NULL,karma int NULL,userlevel int NOT NULL,password varchar(30) NOT NULL,PRIMARY KEY(acctno)Yet when I click on 'Submit', the action page succeeds at inserting them into the table anyway, even though as you can see, some fields are set up NOT to allow NULL values. How do I prevent this from happening? I am using Mac OS X FreeBSD UNIX, Apache, MySQL, and PHP.MySQL Ver 14.12 Distrib 5.0.27, for apple-darwin8.6.0 (powerpc) using readline 5.0Apache/1.3.33 ServerPHP Version 4.4.1Thanks :),diode Quote Link to comment Share on other sites More sharing options...
gluck Posted November 4, 2006 Share Posted November 4, 2006 Do you get null or the values are not inserted to the columns? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 No values (blank) is different that null values. Quote Link to comment Share on other sites More sharing options...
diode Posted November 4, 2006 Author Share Posted November 4, 2006 Yes, if you did not put data into a field, it would still put it into the table. Also, how is no data different than NULL? Anyway, is there a way to not allow this?Thanks :),diode Quote Link to comment Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 No data isn't different that null... but a blank value is still a value. Quote Link to comment Share on other sites More sharing options...
diode Posted November 5, 2006 Author Share Posted November 5, 2006 What's the difference between no data and a blank value?Thanks, diode Quote Link to comment Share on other sites More sharing options...
.josh Posted November 5, 2006 Share Posted November 5, 2006 a variable set to NULL has no data type, nor does it point to any place in the physical memory for which data would be held. An "empty" variable is a variable with a specific data type (like string or integer) that does point to a physical memory address. It is a string just like "abc" or an integer like 123 only it has 0 characters. another way to look at it:Let's say you are this dude in a warehouse full of shelves and on those shelves there are lots of boxes. All of the boxes have labels, or names, on them. These boxes may or may not have something in them. All types of things, or nothing at all. There are also empty spaces on the shelves, where you [i]could[/i] put some more boxes. Now, you carry around a list of these box names on a sheet of paper on a clipboard. It's one of those nice clipboards with a calculator on the top. And a little pen holder. Okay, following this analogy:- The names on the clipboard are your variable names. They reference the specific box on the specific shelf in the warehouse. - A normal variable is like one of these boxes with a label (what type of stuff is in it) on it, sitting on the shelf. - An "empty" variable would be like one of those boxes sitting on the shelf, but it's empty. There's nothing in it. Your clipboard tells you where the box is, and you can find the box just fine, but so far the box doesn't have a label on it, because you haven't put anything into it yet. When you put something into it, you will also put a label on it (integer, string, etc..)- Now let's say you have a few names on your list, but they don't point to any of those boxes. You look and look and look and either someone stole the damn box, or it's just didn't exist. It's some phantom name on your list not pointing to any shelf or box or anything. This is a [i]NULL[/i] variable. Now, I can go get a box from the stack of boxes and stick it on a shelf and associate that phantom name to it, and it magically becomes an empty variable. Then I can put something in it, slap a label on it, and it's a plain old variable. So to recap: An empty variable points to an empty box. It has no data type until you put something in it. A NULL variable points to nothing (so having no data type goes without saying). Now in reality, it's somewhat more complicated than that, but hopefully I have provided you with a good place to start. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 5, 2006 Share Posted November 5, 2006 C_V has given some excellent examples -- the one I like to use involves numeric fields. If you ask someone a question like "how many siblings do you have?", zero is a perfectly valid answer. However, if someone simply doesn't answer the question, the "blank" value would be zero as well. With a NULL value, you'd have no way to differentiate between those who simply didn't complete this question (and may have 3 siblings -- i.e. an _unknown_ number) vs. those who did answer but were an only child. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.