php - Insert on duplicate key update didn't update, instead insert new value -
I have a table with 4 lines, 1 is the primary key with automatic increments, the line is check_id ..
What do I have to do Insert a new data if no data exists and updates data based on ID if it exists. I'm already using it: but enter only a new value Instead, I have the code Is there anything wrong with my update query or my table? This is my code: And this is php code. The database is performing as expected. Every time you get a new, autonombed value in You want to receive behavior, to declare you Once you have done this, along with the additional Checklist on duplicate key updates (check_pos, check_off, check_code) value ('$ name', '$ name ',' $ Code '), check_core =' $ name '
check_id Tried > to the unique key and this is the same,
& lt ;? php $ ew = mysql_query ("choose from pos_unit * where pos_unit_name '% director%'"); $ Line = mysql_num_rows ($ ew); While ($ eq = mysql_fetch_array ($ ew)) {$ pos = $ eq ['pos_unit_name']; $ Checklist = mysql_query ("select from checklist * where check_ok = '$ pos'"); $ Excheck = mysql_fetch_array ($ checklist); $ Poss = $ excheck ['check_pos']; ? & Gt; & Lt; Li & gt; & Lt; div class = "form_grid_12" & gt; & Lt; Label class = "field_title" id = "real" & gt; & Lt ;? Php echo $ eq ['pos_unit_name']; ? & Gt; & Lt; / Labels & gt; & Lt; Div class = "form_input" & gt; & Lt; Input type = "hidden" name = "id []" value = "& lt ;? php echo $ cost ['check_id'] ;;>" & Gt; & Lt; Input name = "condition []" class = "checkbox" type = "checkbox" & lt ;? Php if (echo = $ $ poss) echo "check = 'check'"; ? & Gt; Value = "& lt ;? php echo $ eq ['pos_unit_name'] ;? & gt;" Style = "opacity: 0;" & Gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / li & gt; & Lt ;? Php}? & Gt;
Include 'config.php'; $ Code = $ _POST ['code']; $ Id = $ _POST ['id']; // $ dist = $ _POST ['selectdistarg']; $ Check = $ _POST ['status']; // $ input = $ _POST ['selectinp']; // $ eval = $ _POST ['selectval']; Value in '$ name', '$ name', '$ code in the checklist (check_poose, check_off, check_code) on {$ up = mysql_query (duplicate key), check the foreign currency ($ index = & gt; $) '); Enter (mysql_error ());}
INSERT you get a new record in
check_id Because it's the
primary key of the table And because you have not declared any other
UNIQUE INDEX es, there is never a duplicate key status.
unique index columns that make each row really unique, you delete
check_id and the
primary of the table Key to become
UNIQUE INDEX The Awa can consider.
Comments
Post a Comment