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

AtdtXav atdtxav at yahoo.com
Tue Apr 9 11:34:00 CDT 2002


Thanks for the reply, Anne,

I am using MySQL, and evolt's server.  I don't seem to have
access to the Alter command on the server (as anything relating
to it comes back with an error), and I get a strange error when
I try to create a second unique field with the type TEXT.  I
discovered REPLACE last night, but of course I have to have a
unique field.

Is there some other requirement I have to follow for unique
text?
here's how I've been trying to select and update -

   $checkip = SelectQuery ("ptmratings", "id, ip", "where
ip={$REMOTE_ADDR}", "", "order by id");
   if (in_array( $REMOTE_ADDR, $checkip ) ) {
    print "YES, in array";
    $error = UpdateQuery ("ptmratings", $values, "where
ip=$REMOTE_ADDR");
    }
   else {
    print "NO, not in array";
    $error = InsertQuery ("ptmratings", $values)

Scott Kennedy

--- Anne Thorniley <anne at beerintheevening.com> wrote:
> 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
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/



More information about the thelist mailing list