> Now I have used the following to check if duplicate records exist before
> updating:
> <?php
> // Try and update with posted fields form html form
> $update = mysql_query("UPDATE hosts SET hostname='$_POST[hostname]',
> mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE
> id='$_SESSION[id]'",$db);
> $rows = mysql_affected_rows();
> // Check results of operation
> if($rows == 0) {
>    echo "No matching records found";
> } else {
>    echo "Matching records found"; }
> Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE
> field, wish I would have known it sooner, I wouldn't be so pissed off
> from frustration.

One thing to note here, also... if you update a row with the same exact
information, mysql_affected_rows() will return zero. So, even though a row
is matched and "updated", nothing is really affected. Not sure if that
matters here, but something to be aware of.

---John Holmes...

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to