CodeIgniter Forums
[please help]this SQL syntax make me crazy - 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: [please help]this SQL syntax make me crazy (/showthread.php?tid=41529)



[please help]this SQL syntax make me crazy - El Forum - 05-10-2011

[eluser]rikes_denis[/eluser]
i'm trying to insert a value to my database, everything is fine except the inserting thing. this is my controller function

Code:
$items = $this->okapi_termmodel->get_term()->result();
        var_dump($items);
        $insertIDF = 'INSERT INTO okapi_term(idf) VALUES(?)';
        foreach($items as $item) {
            $this->db->query($insertIDF, $this->idf($item->term));
            }

when i var_dump the $items, it shows all the database perfectly.
but in the end it return this error

Quote:A Database Error Occurred


Error Number: 1062

Duplicate entry '' for key 'term'

INSERT INTO okapi_term(idf) VALUES(-2.1972245773362)

can someone help me???
thanx b4


[please help]this SQL syntax make me crazy - El Forum - 05-10-2011

[eluser]boltsabre[/eluser]
Just off the top of my head, perhaps your have your table column set to only accept unique values, and your trying to insert a value that already exists in the table? Or try investigating what Error Number 1062 means in detail.


[please help]this SQL syntax make me crazy - El Forum - 05-10-2011

[eluser]rikes_denis[/eluser]
no, im not settings a unique value in my database
im still trying search the web.

the id is auto increment and bigint type, is this might be a problem?


[please help]this SQL syntax make me crazy - El Forum - 05-10-2011

[eluser]troy_mccormick[/eluser]
[quote author="rikes_denis" date="1305062065"]A Database Error Occurred


Error Number: 1062

Duplicate entry '' for key 'term'

INSERT INTO okapi_term(idf) VALUES(-2.1972245773362)[/quote]

The error message says it all, in this case. It is telling you that it is trying to insert a blank value for the field term, but there is already a record in the database with a blank term value and it cannot insert this new row as it would be a duplicate (as you must have term marked as unique...).

That's all there is to it...


[please help]this SQL syntax make me crazy - El Forum - 05-11-2011

[eluser]rikes_denis[/eluser]
it turns out that i have indexes the database. i already fix it with delete the index
thanx all for the respons, you'll the best
gbu ^^