Shaun wrote:
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; }
What would be a graceful way to handle it, in your opinion? You have the mysql_error() and mysql_errno() functions. You can just do you're INSERT and then check for errno 1062 for a duplicate key and act accordingly. Define "graceful" for us.
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php