[thelist] PHP: Insert or Replace (upon duplicate IP)

Anne Thorniley anne at beerintheevening.com
Tue Apr 9 03:32:01 CDT 2002


Hi Scott,

> I can successfully INSERT new data into my table (ptmratings).
> However, I don't want someone with the same IP adding multiple
> ratings.  Can anyone direct me to code that checks for a
> duplicate and if none is found, inserts a new row?

If you're using MySQL, and you put a unique index on the IP address
column, you could look into the REPLACE syntax, which will insert the
row if no unique constraints are violated, otherwise update the values.

See
http://mysql.com/documentation/mysql/bychapter/manual_Reference.html#REPLACE

Other DBs may have similar ways to do it (don't think Oracle does though).

Anne


--
Now you've reached the point where she sees through you -
Your low esteem and lack of self-control



More information about the thelist mailing list