Re: multiple fields all unique?

From: Date: Wed, 04 Feb 2004 16:40:31 +0000
Subject: Re: multiple fields all unique?
References: 1 2 3 4 5 6 7  Groups: php.db 
Request: Send a blank email to php-db+get-32790@lists.php.net to get a copy of this message
From: "Jas" <jason.gerfen@scl.utah.edu> > 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...

« previous php.db (#32790) next »