Page 1 of 1

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

Posted: Tue Jan 18, 2011 6:54 am
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

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

Posted: Tue Jan 18, 2011 9:41 am
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?

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

Posted: Tue Jan 18, 2011 3:59 pm
by surrender
Yes thats true. i want using sqlquery

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

Posted: Wed Jan 19, 2011 1:42 am
by Darhazer
You need an UNIQUE key on the field, than you can use
INSERT INTO ... ON DUPLICATE KEY UPDATE ...