I have a table with a primary key id_form that is an autoincrement field.
I have a form that will insert into that table. I want to reuse the same form to edit the records. So my form has an hidden input that has value=''
when I am inserting a new line in the table or value=<id of the edited row>
while editing.
My query is the following:
INSERT INTO form_header SET
id_form= :id_form,
nome_form=:nome_form,
mainDescr=:mainDescr,
step=:step,
visibility=:visibility,
start=:start,
end=:end,
autore=:autore,
wizard_token=:wizard,
last_records=0
ON DUPLICATE KEY UPDATE
nome_form=:nome_form,
step=:step,
visibility=:visibility,
start=:start,
end=:end
If I try to insert a new row I will pass id_form=''
but I get:
Incorrect integer value: '' for column 'id_form' at row 1
My table structure is the following (only the relevant field):
Field Type Null Key Default Extra
id_form int NO PRI NULL auto_increment
So how do I pass the id when it is empty? Without the ON DUPLICATE KEY
part I'd only skip the field but now I have to pass it so that mysql can check if I am inserting or updating a row. Or there is another way to do it?