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
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 :)


Andy (mod)
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!