HELP Check if already exist, then update or if no then creat

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
surrender
Forum Newbie
Posts: 2
Joined: Tue Jan 18, 2011 6:46 am

HELP Check if already exist, then update or if no then creat

Post by surrender »

First, hi all, i am new here.

i am glad to be here :D


Okay so, i have problem with my code, pls see the image

Image

i want to check if the value is already inputted, then it will update, if its not exist than it will create some value.


Thank you for your help.

thanks
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: HELP Check if already exist, then update or if no then c

Post by Peter Kelly »

I'm not sure how to do that in MySQL but you can definitely do it in PHP. Is it required you do it using a SQL query?
surrender
Forum Newbie
Posts: 2
Joined: Tue Jan 18, 2011 6:46 am

Re: HELP Check if already exist, then update or if no then c

Post by surrender »

Yes thats true. i want using sqlquery
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: HELP Check if already exist, then update or if no then c

Post by Darhazer »

You need an UNIQUE key on the field, than you can use
INSERT INTO ... ON DUPLICATE KEY UPDATE ...
Post Reply