[snip]You're not going to be able to fetch anything from the result set because you're excuting an UPDATE query, not a SELECT.
You also do not want to die() when the query fails, otherwise you won't be able to react to the error. Execute the query, then check mysql_error() for a value. If it contains a value, then the query failed more than likely because of a duplicate key.
Well looks like I need to brush up on my php - mysql functions. =)
For anyone that has been following this thread here is a simple way to catch the duplicate and show the user the contents:
<?php
$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();
if(!@mysql_errno($update)) {
echo "No match found";
} else {
echo "Match found";
$error = preg_match("/^[']$/",mysql_errno($update));
$sql = mysql_query("select * from hosts where id = $error")
while($x = mysql_fetch_array($sql)) {
list($id,$host,$mac,$ip,$vlan) = $x; }
}
?>
Might want to check the preg_match string to look for everything between ' and ' but other than that you should be able to list the record that your update statement is having a problem with.
HTH
Jas
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php