Update record if exist, else insert in MySQL -


I know, this question was asked many times and answered as well ..
However, my problem Is more specific and I could not find a suitable solution.

My table (designated as pages) is like that;

Strong> I've changed this to a unique ) similar to the post.

I mean I need to enter / record the based record on the Slug record.

Example Current Data:

  ID | Title | Content | Slug | -------------------------------------- 1. Mainpage | Some HTML Home page   

If the posted data has title = childpage, content = html .., slug = mainpage , then record me the previous record (title and content) ), But if the data has title = main page, content = html ..., slug = other_slug then I have to insert this data in a new form with a new ID.

UPDATE <

The most appropriate thing I can imagine Slug is to create a unique index on the column

  Add unique key alley to the optional table page;   

The reason for this is simple: if it is not unique, then "manpepe" can be more than one slug ... which should be updated ??

Use the segment again:

  The key to duplicate content is $ = content at $ content    page values ​​($, $ Title, $ content, $ slug) INSERT div> 

Comments