Help Column cannot be null |
Hello guys i just need your help about my form having error submitting it
Column 'date' cannot be null and here's my code: PHP Code: public function create_purchase(){ Model PHP Code: public function add_purchase($data_list){ Database Table PHP Code: CREATE TABLE `purchases` ( Hope you can help me. Thanks!
CREATE TABLE `purchases` (
`purchase_id` int(11) NOT NULL AUTO_INCREMENT, `sup_name` varchar(50) NOT NULL DEFAULT '', `date` date NULL DEFAULT '', `qty` int(11) NOT NULL DEFAULT '', `price` decimal(12,2) NOT NULL DEFAULT '', `date_expired` date NOT NULL DEFAULT '', // Others Website: http://avenir.ro
As Avenirer points out, you could change the definition of the column to accept null values. I'd add that your default values should be valid values of the columns' data types (e.g. date null default '0000-00-00' or int(11) not null default 0).
In your create_purchase() method, you should validate your data before passing it to $this->model_products->add_purchase(). If you don't want to use form validation (or don't want to generate an error for a null value on a field defined with 'not null' in your database), I would recommend creating a method in your model to perform some basic prep on the data before it is passed to the database methods, so you can make sure the data isn't going to generate database errors. |
Welcome Guest, Not a member yet? Register Sign In |