Update record if exist, else insert in MySQL
===

I know, this question was asked many times and answered as well..<br>
But, my problem is more specific and i couldn't found a proper solution.

My table (named as pages) is like that;

    id (int)
    title (text)
    content (text)
    slug (text)

I need to update my record if slug (not unique or primary) is same as posted.

I mean i need to update/insert my record **based** on *slug* record.

Eg. current data:

      id  |  title  |  content  |  slug  |
    --------------------------------------
      1  |  MainPage| some html | mainpage

if posted data has `title=ChildPage, content=html.., slug=mainpage` then i need to update previous record (title and content records), but if data has `title=MainPage, content=html.., slug=other_slug` then i need to insert this data as new with a new id.