Handling MySQL errors

From: Date: Sat, 03 Jul 2004 15:08:27 +0000
Subject: Handling MySQL errors
Groups: php.general 
Request: Send a blank email to php-general+get-189630@lists.php.net to get a copy of this message
Hi, Is there a way to handle MySQL errors gracefully such as a duplicate entry into a UNIQUE field, the method I've been using seems a little laborious... //see if user exists $query = "SELECT * FROM users WHERE Username = '".$_POST[username]."'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if($num > 0){ $error = "Username already exists, please choose a another one"; header("Location: add_user.php?error=$error"); exit; } Thanks for your help

« previous php.general (#189630) next »