Will,

When you connect through dbi, set raiseError to 1. Normally a dbi error
message goes to stdout. To capture it you can do something like this
(untested):

if(eval{$csr_insertUser($userName...)} || $@){
        $@ =~ m/Unique Constraint Failed/ ;  ### or whatever mySql error
reads like
        $insertError = $1;
        # check $insertError and decide what to do from there...
}

Of course this is only if you're too classy to use the "brute force and
ignorance" approach of first selecting the username that the person has
chosen, and only trying to insert it if the select returns zero rows.

Tim

-----Original Message-----
From: Will [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 07, 2003 1:57 PM
To: DBI Users
Subject: Can DBI be used to validate input?


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...

Thanks,

Will

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Reply via email to