I'm creating the table below, but how do I include "James" as an entry to be automatically added when the table is created? I hope my question is clear.
CREATE TABLE IF NOT EXISTS list (
id INT NOT NULL AUTO_INCREMENT,
names VARCHAR(50), PRIMARY KEY (id)
)
Try something like this
DROP TABLE IF EXISTS `list`;
CREATE TABLE `list` (
`list_id` int(11) NOT NULL AUTO_INCREMENT,
`label` varchar(250) DEFAULT NULL,
`code` varchar(250) DEFAULT NULL,
PRIMARY KEY (`list_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
/*Data for the table `list` */
insert into `list`(`list_id`,`label`,`code`) values (1,'Chest','chest');
After you create table , you should use insert into to populate it with data :
CREATE TABLE IF NOT EXISTS list (id INT NOT NULL AUTO_INCREMENT, names VARCHAR(50), PRIMARY KEY (id));
INSERT INTO `list` (`names`) VALUES('James');
To be more readable :
CREATE TABLE IF NOT EXISTS list (id INT NOT NULL AUTO_INCREMENT, names VARCHAR(50), PRIMARY KEY (id));
INSERT INTO `list` (`id`,`names`) VALUES('null','James');
I would suggest to make use of mysqli_multi_query. CREATE the table first and then do the INSERT.