CodeIgniter Forums
Incorrect integer value: '' for column 'id' at row 1 - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Incorrect integer value: '' for column 'id' at row 1 (/thread-54479.html)

Incorrect integer value: '' for column 'id' at row 1 - El Forum - 09-10-2012

help i got this error when i try to insert a new item in my table.

my form:
<div class="main">
<div class="main-content">
<h1 class="block">MEMBERSHIP LOGIN</h1>
<div class="column1-unit">
<h1>Create Free Account Now</h1>
<div class="loginform">
&lt;?php echo form_open('homepage/addNewMember'); ?&gt;
<p><label class="top">Reffered By:</label><br />
&lt;input type="text" name="reffered" tabindex="1" class="field" value="" placeholder="Reference Username" /&gt;

<p><label class="top">Username:</label><br />
&lt;input type="text" name="username" tabindex="1" class="field" value="" placeholder="Desired Username" /&gt;

<p><label class="top">Last Name</label><br />
&lt;input type="text" name="lastname" tabindex="2" class="field" value="" placeholder="Your Last Name" /&gt;

<p><label class="top">First Name:</label><br />
&lt;input type="text" name="firstname" tabindex="1" class="field" value="" placeholder="Your First Name" /&gt;

<p><label class="top">Middle Name:</label><br />
&lt;input type="text" name="middlename" tabindex="1" class="field" value="" placeholder="Your Middle Name" /&gt;

<p><label class="top">Email Address:</label><br />
&lt;input type="text" name="email" tabindex="1" class="field" value="" placeholder="[email protected]" /&gt;

<p><label class="top">Mobile Number:</label><br />
&lt;input type="text" name="contact" tabindex="1" class="field" value="" placeholder="xxxx-xxx-xxxx" /&gt;

<p><label class="top">Gender: </label><br />
<select name="gender">
<option value="">---</option>
<option value="Male">Male</option>
<option value="Female">Female</option>

<p><label class="top">Password: </label><br />
&lt;input type="password" name="password" tabindex="1" class="field" value="" placeholder="8 to 16 characters only" /&gt;

<p><label class="top">Confirm Password: </label><br />
&lt;input type="password" name="passcon"tabindex="1" class="field" value="" placeholder="Re-type password" /&gt;

<p>&lt;input type="submit" name="cmdweblogin" class="button" value="CREATE" /&gt;&lt;/p>
my controller method

public function addNewMember(){
my model method

public function addNewMember(){
$data = array(
'id' => '',
'username' => strtolower($this->input->post('username')),
'lastname' => ucwords($this->input->post('lastname')),
'firstname' => ucwords($this->input->post('firstname')),
'middlename' => ucwords($this->input->post('middlename')),
'gender' => $this->input->post('gender'),
'email_address' => strtolower($this->input->post('email')),
'mobile_number' => $this->input->post('contact'),
'reffered_by' => $this->input->post('reffered'),
'password' => md5($this->input->post('password')),
'date_registered' => date('Y-m-d h:iConfused')
return $this->db->insert('tbl_member',$data);
my table structure
CREATE TABLE tbl_member(
id int unsigned auto_increment,
username varchar(50) unique not null,
lastname varchar(50) not null,
firstname varchar(50) not null,
middlename varchar(50) not null,
gender enum('Male','Female'),
email_address varchar(50) not null,
mobile_number int not null,
reffered_by varchar(50),
password varchar(50) not null,
date_registered datetime

Incorrect integer value: '' for column 'id' at row 1 - El Forum - 09-11-2012

You're trying to insert an empty string into an integer column. The ID is an auto-increment column that will populate itself, so leave the ID out of the insert.

Incorrect integer value: '' for column 'id' at row 1 - El Forum - 09-11-2012

ok thanks

Incorrect integer value: '' for column 'id' at row 1 - El Forum - 09-11-2012

No problem. Next time, please put your code in code tags like my sig shows so it will be easier to read.