At 5:46 PM -0500 6/27/01, Pete Kuczynski wrote:
>Thanks Paul!
>ps works great!
>I modified the database with a UNIQUE column like you recommended
>earlier, this will now help in the PHP script to trap the duplicate
>entry and advise the user of the dup.

But if hostname now has a UNIQUE index on it, it won't even be possible
for your table to have duplicate hostname values, other than NULL.

Probably all you need to do is just go ahead and try to insert the record,
and if mysql_affected_rows() is 0, it was a duplicate and was rejected.

>
><?
>     // check for duplicate row
>     $query = "SELECT hostname, COUNT(*) AS count FROM asset
>               GROUP BY hostname HAVING count > 1
>     $result = mysql_query($query);
>             // check if row is returned, if yes error, if no insert
>             if (mysql_num_rows($result) != 0) {
>                     echo "error";
>             } else {
>                     // DO INSERT
>             }
>     ?>
>
>Pete


-- 
Paul DuBois, [EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to