The following code supposedly works. Unfortunately, it won’t work for me. Do you see any error in this?
CREATE TABLE `admins` (
`admin_id` int(11) NOT NULL auto_increment,
`admin_username` varchar(40) NOT NULL default '',
`admin_password` varchar(40) NOT NULL default '',
`admin_status` varchar(40) NOT NULL default 'Offline',
`admin_last_login` varchar(40) NOT NULL default '',
PRIMARY KEY (`admin_id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
INSERT INTO `admins` VALUES (1, 'admin', 'admin', 'Offline', '');
(This is standard SQL or phpmyadmin, not PHP etc)
what doesn’t work the table creation or the insert?
also, flaky in my opinion, you are creating column types that are NOT NULL but then make an empty value the default value. Why not just allow them to be NULLable then?
You are using old syntax for the CREATE TABLE. The keyword TYPE has been deprecated and you should use ENGINE instead:
CREATE TABLE `admins` (
`admin_id` int(11) NOT NULL auto_increment,
`admin_username` varchar(40) NOT NULL default '',
`admin_password` varchar(40) NOT NULL default '',
`admin_status` varchar(40) NOT NULL default 'Offline',
`admin_last_login` varchar(40) NOT NULL default '',
PRIMARY KEY (`admin_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 ;
INSERT INTO `admins` VALUES (1, 'admin', 'admin', 'Offline', '');
I believe you also want to use DEFAULT NULL, not ‘’. I believe this will actually cause a select of IS NULL to not return those rows, if queried.
r937
October 5, 2012, 11:25am
5
actually, for username and password, these should ~not~ be DEFAULT NULL
how much sense does it make to add an admin to the table with a NULL username and password???
r937:
actually, for username and password, these should ~not~ be DEFAULT NULL
how much sense does it make to add an admin to the table with a NULL username and password???
But why change up the design from normal columns if it should never be null. It doesn’t make sense for it to be an empty string either.
r937
October 8, 2012, 5:11pm
7
i’m afraid i don’t understand what you mean by “normal” columns
DEFAULT ‘’ is not normal
NOT NULL with no default is normal