Welcome Guest, Not a member yet? Register   Sign In
sql error. How to add autoincrement id to the INSERT
#1

[eluser]linderox[/eluser]
I followed by this IBM article http://www.ibm.com/developerworks/openso...index.html
but i receive this answer from the mysql database
Code:
Error Number: 1062

Duplicate entry '0' for key 1

INSERT INTO `guestbook` (`name`, `email`, `text`, `ipaddress`, `date`) VALUES ('assa', 'Alex', '[email protected]', '127.0.0.1', '2009-02-26 08:53:35')

here is a database structure
Code:
CREATE TABLE `guestbook` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(128) NOT NULL,
  `email` varchar(255) NOT NULL,
  `text` text NOT NULL,
  `date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `ipaddress` varchar(32) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;

this is Insert function:
Code:
function addContact(){
  $now = date("Y-m-d H:i:s");
  $data = array(
    'name' => $this->input->xss_clean($this->input->post('name')),
    'email' => $this->input->xss_clean($this->input->post('email')),
    'text' => $this->input->xss_clean($this->input->post('notes')),
    'ipaddress' => $this->input->ip_address(),
    'date' => $now
  );

  $this->db->insert('guestbook', $data);
}

if i use id in this data array it will insert all data succsesfully, but I don't want to care about id number - it is primary auto_increment key. How to solve problem?
#2

[eluser]pistolPete[/eluser]
Try the following:
Code:
$data = array(
    'id' => '',
    'name' => $this->input->xss_clean($this->input->post('name')),
    'email' => $this->input->xss_clean($this->input->post('email')),
    'text' => $this->input->xss_clean($this->input->post('notes')),
    'ipaddress' => $this->input->ip_address(),
    'date' => $now
  );
#3

[eluser]linderox[/eluser]
[quote author="pistolPete" date="1235658896"]Try the following:
Code:
$data = array(
    'id' => '',
    'name' => $this->input->xss_clean($this->input->post('name')),
    'email' => $this->input->xss_clean($this->input->post('email')),
    'text' => $this->input->xss_clean($this->input->post('notes')),
    'ipaddress' => $this->input->ip_address(),
    'date' => $now
  );
[/quote]

nothing happend - the same error I recieved.

on another forum on man recommend me to make this one
Code:
SHOW TABLE STATUS LIKE 'guestbook'
and that command says that my db corrupted. What I should do now?
#4

[eluser]pistolPete[/eluser]
[quote author="linderox" date="1235659622"]What I should do now?[/quote]
How about repairing the database?




Theme © iAndrew 2016 - Forum software by © MyBB