Gossamer Forum
Home : General : Databases and SQL :

MySQL search query not returning records

Quote Reply
MySQL search query not returning records
I am running a CGI script written in PERL that has the following lines to conduct a search of a MySQL database.

my $searchWhat = $q->param('searchWhat');
my $dsn = "DBI:$driver:database=$dbf:host=$host";
my $dbh = DBI->connect($dsn, $user, $password) or die "$DBI::errstr\n";
my $sql = "SELECT fname, lname, suffix, specialty, rank from $dbf.$table where
lname=?";
my $sth = $dbh->prepare($sql) or Disconnect_Die($dbh, "$DBI::errstr\n");
$sth->execute("%$searchWhat%") or Disconnect_Die($dbh, "$DBI::errstr\n");

When the script runs with the SELECT statement without the where clause, the records are returned. The script is called from a form where the user types in search criteria.

Can you help me pinpoint the problem? I'm very new to database programming.
Quote Reply
Re: [alb215] MySQL search query not returning records In reply to
I'm confused. From what I understand, you would need a query like;

SELECT * FROM Table WHERE Field LIKE '%$searchWhat%'

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates