Will [[EMAIL PROTECTED]] wrote: > I am developing a registration area for a members site > that will interface with a MySQL DB users table, and I > ran into a problem. Note that I am using DBI > as my DB Driver. > > Suppose the user tries to register with a username > that has already been taken. I need a way to kick > back an error message to them. I tried setting the > username field in the usrs table to UNIQUE, so that > might help if someone tried to insert something > already taken... I was thinking that if MySQL kicks > back an error message, then DBI might be able to > recongize it in such a way that I could use the return > value... I dont know if that is completely feasible > though... there may be other, better ways anyway... > so I'm all ears...
You have the right idea - create your username field UNIQUE and let MySQL kick out the error - it's up to you to catch the error and make sure the error was caused by a user trying to enter a dup username. This topic has been discussed at length in the last week or two - find and search the archives for UNIQUE and I'm sure you'll find the relevant conversations. Read the perldocs by doing perldoc DBI at a command prompt, and search for 'RaiseError' and 'eval' - you'll find a section with 'Transaction' in the title. That will show you how to execute some DBI code (an INSERT perhaps), and catch any errors in DBI statements (including db errors, such as attempting to insert a duplicate key) using 'eval'. HTH. -- Hardy Merrill Senior Software Engineer Red Hat, Inc.
