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:

 Checklist on duplicate key updates (check_pos, check_off, check_code) value ('$ name', '$ name ',' $ Code '), check_core =' $ name '  

but enter only a new value

Instead, I have the code check_id Tried > to the unique key and this is the same,

Is there anything wrong with my update query or my table?

This is my code:

  & 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;   

And this is php code.

  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 ());}    

Enter the search_check =' $ names' ") or die

The database is performing as expected.

Every time you get a new, autonombed value in 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.

You want to receive behavior, to declare you Once you have done this, along with the additional 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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -