joostvanveen / build-a-cms-with-codeigniter

Source code for the Tutsplus course 'Build a CMS with Codeigniter'
53 stars 55 forks source link

Adding a page #9

Closed ghost closed 10 years ago

ghost commented 10 years ago

Good day, I know that it has been a while since you have given this course, but I would like to say that it is brilliant. Thank you for your efforts. That being said, I am getting a error 1364 each time I try to create a new page. I spent 2 days now going thought the code and I can figure it out. I have also compared with your source code and cant find the error. See below.

A Database Error Occurred Error Number: 1364 Field 'order' doesn't have a default value INSERT INTO pages (title, slug, body, parent_id) VALUES ('yesy', 'test', 'uoshgushfg', 0) Filename: C:\xampp\htdocs\onpoint_ci\system\database\DB_driver.php Line Number: 330

I checked the page_m model and the page controller as well. The view is set correctly but i dont know where i went wrong. Your assistance would be greatly appreciated.

Thanks

joostvanveen commented 10 years ago

Hi @blackcarpet ,

Thanks :)

The error you're getting is a strict MySQL error. MySQL is confused because you are not specifying the value for the 'order' column, while there is no default value specified for that column. Just specify a default value of 0 for the 'order' column and you should be good. Actually, a default value is specified in the SQL code for this course: https://github.com/joostvanveen/build-a-cms-with-codeigniter/blob/master/sql/cms.sql

DROP TABLE IF EXISTS `pages`;
CREATE TABLE `pages` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `order` int(11) unsigned NOT NULL DEFAULT '0',
  `body` text NOT NULL,
  `parent_id` int(11) unsigned NOT NULL DEFAULT '0',
  `template` varchar(25) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

Happy coding!