Will wrote:
> Greets Folks,
> 
> 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 or two.  Note that I am using DBI as my DB Driver.
>
> ...
> 
> Second, suppose they try 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...

$DBI::err will have the database engine error code from the last call.
You'll have to figure out which value MySQL uses for unique constraint
violation. You can then test for that in your script.

   $dbh->{RaiseError} = 0;           # don't die on error
   $dbh->do('insert into user (name) values ?', undef, $username);
   if ($DBI::err == 999) {           # replace 999 with the correct error
code!
      print "Duplicate user\n";
   elsif ($DBI::err) {
      print "Unexpected error: $DBI::errstr\n";
   }

See perldoc DBI under the heading "METHODS COMMON TO ALL HANDLES"

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to