On Wednesday June 11 2003 10:09 am, Greenhalgh David wrote:
> On Wednesday, June 11, 2003, at 02:10  am, Annie wrote:
> > no i want to ask what if someone enters a firstname and last name
> > which doesnot exist in the database...in that case how i can verify
> > and print an error msg that the data doesnot exist for this first name
> > and last name.
>
> Well a fairly simple way would be to check to see if there is a return
> from the query...
>
> > use strict;
> > use DBI;
> > .
> > .
> > .
> > my $dbhandle=DBI->connect("DBI:mysql:data_base_name", "username",
> > "password");
> > my $query = "SELECT * FROM table_name WHERE lastname = '$a2' AND
> > firstname = '$a1'";
> > my $statementhandle = $dbhandle->prepare($query);
> > $statementhandle->execute;
>
> my @return
>
> > while (($lastname, $firstname, $age, $address) =
> > $statmenthandle->fetchrow()){
>
> @return = ($lastname, $firstname, $age, $address)
>
> > }
>
> if ([EMAIL PROTECTED]){
>
> PRINT ERROR MESSAGE HERE
> }
> else {
>
> PRINT DATABASE DATA HERE
> }


along the same lines , the dbi  method  rows

 $statementhandle->execute;

my $results =  $statementhandle->rows;

if( $results <= 0 )  { do an error message} else { print " you're in the 
database";}


Greg




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

Reply via email to