Results 1 to 2 of 2
I want to do following in PerCGI:-
i) Want to validate "username" is already exists in DataBase or not?
ii) Can I check whether $sth contains some values or not ...
- 02-02-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
how to validate username with DataBase in PerlCGI
I want to do following in PerCGI:-
i) Want to validate "username" is already exists in DataBase or not?
ii) Can I check whether $sth contains some values or not from below mentioned statement?
iii) If $sth is not containing any value, means $user is not exists in Database then what'll fetchrow_array return.
$sql = Select * from userinfo where username=$user;
my $sth = $dbh->prepare($sql);
$sth->execute;
my @row = $sth->fetchrow_array
Please help me
Thanks
- 02-02-2008 #2
First off, remember to quote your assignment to $sql.
Secondly, so you want to know the number of rows that some query returns. This can be done by changing your SQL query and doing the following:
$count now contains the number of rows that have a username of $user.Code:my $sql = "SELECT COUNT(*) FROM userinfo WHERE username = ?"; my $sth = $dbh->prepare($sql); $sth->execute($user); my $count = $sth->rows;
Alternatively, as per the CPAN documentation of the DBI module:
You might prefer fetchrow_arrayref, because:
Originally Posted by DBI Documentation
And an undef is simple to check for.
Originally Posted by DBI Documentation DISTRO=Arch
Registered Linux User #388732


Reply With Quote