CodeIgniter Forums
MYSQL Error# 1364 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MYSQL Error# 1364 (/showthread.php?tid=56065)



MYSQL Error# 1364 - El Forum - 11-23-2012

[eluser]brandonjjon[/eluser]
Hello Everyone,

I'm attempting to insert data into my database and the code I wrote is producing this error. I have added the code and the error into this pastie document: http://beta.pastie.org/5426372

I've never had this issue with previous codeigniter applications! Could anyone provide insight on why this is happening? I don't even know why it's telling me anything about an email field. I have no idea why.

Kind Regards,
Brandon


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]ahmed.alsiddig[/eluser]
hi ..
i need more information 2 help
do u have email field in database ??


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]brandonjjon[/eluser]
Yes there is an email field in the table. But this is merely code to insert $website into the `websites` field. Nothing about the email field..


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]hungryhippo[/eluser]
When you are inserting in to the database, column 'email' needs a value. Error due to provided no value for this column


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]brandonjjon[/eluser]
But I'm not even wanting to insert any data into this column...

I provided a "where" statement to insert it into the correct row. The email field on this particular row is already populated.

The goal is to insert $website into the `websites` field.


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]hungryhippo[/eluser]
So you are wanting to update an existing row rather than insert a new one? You will want to use "update" rather than "insert"


MYSQL Error# 1364 - El Forum - 11-24-2012

[eluser]Aken[/eluser]
[quote author="brandonjjon" date="1353799334"]But I'm not even wanting to insert any data into this column...

I provided a "where" statement to insert it into the correct row. The email field on this particular row is already populated.

The goal is to insert $website into the `websites` field.[/quote]
When you created the email column, you specified that it must have a value (aka NOT NULL). You need to provide a default value when doing inserts, even if you don't want to add a value, OR modify the database column to accept null values.


MYSQL Error# 1364 - El Forum - 11-25-2012

[eluser]PhilTem[/eluser]
You can't perform an insert with a where. The only thing you can do is updating or deleting a row with a where statement.

So you either want this code

Code:
$data = array(
    'websites' => $website
}
$this->db->insert('bf_users', $data);

or this code

Code:
$data = array(
    'websites' => $website
}
$this->db->where('id', $this->current_user->id)->update('bf_users', $data);

Yet guessing from your post you want to use the second code snippet.