I am working on a bug(?) for a few hours now, but couln’t fix it.
This is my code:
if(!$this->db->get_where('merken',array('m_merken' => $brand))->count_all_results()){
$insetData = array('m_name' => $brand);
$this->db->insert('merken', $insetData);
}
$brand contains ‘Acer’ in this preview.
A Database Error Occurred
Error Number: 1054
Unknown column ‘Acer’ in ‘where clause’
SELECT * FROM (`merken`) WHERE `m_name` = Acer
I want to check if it already exists, but it won’t work very well.
Without quotes, your statement:
Acerrefers to a column-name. If your intent is a string literal, put it in single-quotes, as in:Also, as a matter of good programming practice, avoid
SELECT *, better toSELECTeach column you want to return, even if the list is lengthy.— EDIT —
I suspect I’m missing the point… the SQL is generated. Two things to check:
Is
m_namecorrectly declared as astring/varchar/charfield?Failing that, try literally setting the brand name to
'Acer', with the quote marks. I doubt this is a reasonable solution, though.