SQL Question regarding not null defaults.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

SQL Question regarding not null defaults.

Post by mmc01ms »

Hey gang, I was inserting a customer into my database from my form and the final two values nfor the validated and rank coloumn i entred as null, this caused problems stating that i couldn't do this. However in my script i have a default value for if a null is entered. my sql script is below.

Code: Select all

create table customers
(customer_id int(6) not null auto_increment primary key,
first_name varchar(20) not null default'',
surname varchar(20) not null default'',
initial varchar(4) not null default'',
address_line_one varchar(25) not null default'',
address_line_two varchar(25) not null default'',
city varchar(15) not null default'',
county varchar(15) default'',
postcode char(8) not null default'',
home_phone_number char(11) not null default'',
mobile_number char(11) not null default'',
email varchar(40) not null default'',
date_of_birth date not null default'0000-00-00',
username varchar(50) not null default '',
password varchar(20) not null default'',
validated int(1) not null default '0',
rank int(1) not null default '1');
any ideas guys?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

null is different to 0, the last two fields in your table are of type int - maybe want to change them to tinyint(1) since they will just be 1 or 0. Then make sure you use 1 or 0 instead of null.
Post Reply