CodeIgniter Forums
A Database Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: A Database Error (/thread-12363.html)



A Database Error - El Forum - 10-16-2008

[eluser]umefarooq[/eluser]
Hi
im inserting data in table it gives me following error
Quote:A Database Error Occurred

Error Number: 1048

Column 'id' cannot be null

where id is primary key when i comment var id from model it insert the data but key is always 0.


A Database Error - El Forum - 10-16-2008

[eluser]Derek Allard[/eluser]
Do you want to set that column to auto-increment?


A Database Error - El Forum - 10-16-2008

[eluser]umefarooq[/eluser]
ya id column is primary key and also auto increment but i dont know what and where is problem because first time im using CI and i want to carry on for my rest of projects. by reading the user manual its look nice.


A Database Error - El Forum - 10-16-2008

[eluser]Derek Allard[/eluser]
What does your insert code look like?


A Database Error - El Forum - 10-16-2008

[eluser]umefarooq[/eluser]
here is my model code

Code:
class FormModel extends Model {
        
        var $id;
        var $width;
        var $height;
        var $scalecontent;
        var $firstpage;
        var $alwaysopen;
        var $autoflip;
        var $fliponclick;
        var $staticshadow;
        var $dynamicshadow;
        var $movedspeed;
        var $closespeed;
        var $gotospeed;
        var $pageback;
        var $loadondemand;
        var $cachePage;
        var $cachesize;
        
        function FormModel(){
            parent::Model();
        }
        
        function insert_entry(){
            
            print_r($_POST);

            $this->width = $this->input->post('width');
            $this->height = $this->input->post('height');
            $this->scalecontent = $this->input->post('scalecontent');
            $this->firstpage = $this->input->post('firstpage');
            $this->alwaysopen = $this->input->post('alwaysopen');
            $this->autoflip = $this->input->post('autoflip');
            $this->fliponclick = $this->input->post('fliponclick');
            $this->staticshadow = $this->input->post('staticshadow');
            $this->dynamicshadow = $this->input->post('dynamicshadow');
            $this->movedspeed = $this->input->post('movedspeed');
            $this->closespeed = $this->input->post('closespeed');
            $this->gotospeed = $this->input->post('gotospeed');
            $this->pageback = $this->input->post('pageback');
            $this->loadondemand = $this->input->post('loadondemand');
            $this->cachePage = $this->input->post('cachePage');
            $this->cachesize = $this->input->post('cachesize');
            
            $this->db->insert('flipp_settings',$this);
        }
        
        
    }



A Database Error - El Forum - 10-16-2008

[eluser]Derek Allard[/eluser]
And your id is set to autoincrement? Are you sure? Could you add
Code:
echo $this->db->last_query();
after an insert and see what comes up?


A Database Error - El Forum - 10-16-2008

[eluser]umefarooq[/eluser]
with this model when i want to insert the data it give me error Column ‘id’ cannot be null but when i comment the var id than it insert the data but id is 0 always.


A Database Error - El Forum - 10-16-2008

[eluser]Derek Allard[/eluser]
And your id is set to autoincrement? Are you sure? Could you add
Code:
echo $this->db->last_query();
after an insert and see what comes up?


A Database Error - El Forum - 10-16-2008

[eluser]Seppo[/eluser]
I'll ask two questions, if you don't mind...
Can you run "DESCRIBE flipp_settings" and post the results? Are you using MySQL or other DB engine?