actually this already worked and i have no idea what i’ve changed so that i run into this problem now. Tried nearly everything.
The case:
I have the following query. The variable $DB-id is an empty string if the content i want to save is new. The field module_id is my primary key. What happens is that this query always updates the row with the module_id => 0.
The problem
Passing an empty variable as the primary key always updates row 0 instead of inserting a new one.
$this->db->query("INSERT INTO modules_text
(
module_id,
module_content,
module_page_idx,
module_post_id
)
VALUES (
'{$DB_id}',
'{$content['text']}',
'{$content['idx']}',
'{$post_id}'
)
ON DUPLICATE KEY
UPDATE module_content = '{$content['text']}',
module_page_idx = '{$content['idx']}'
");
Does anybody have an idea how i can tell MYSQL to create a new row??? Any help is very appreciated!!!! Thank you very much!!!
Saludos Sacha!
You may need to set your primary key field to auto increment. An example is below.